コード例 #1
0
void CTest::x_TestFormats(void)
{
    const char* module1   = "module";
    const char* module2   = "foo";
    const char* class1    = "class";
    const char* function1 = "function";

    CNcbiDiag m0_c0_f0;
    CNcbiDiag m1_c0_f0;
    CNcbiDiag m2_c0_f0;
    CNcbiDiag m1_c1_f0;
    CNcbiDiag m0_c1_f0;
    CNcbiDiag m1_c0_f1;
    CNcbiDiag m0_c0_f1;
    CNcbiDiag m0_c1_f1;
    CNcbiDiag m1_c1_f1;

    m1_c0_f0 << MDiagModule(module1);
    m2_c0_f0 << MDiagModule(module2);
    m1_c1_f0 << MDiagModule(module1);
    m1_c0_f1 << MDiagModule(module1);
    m1_c1_f1 << MDiagModule(module1);

    m1_c1_f0 << MDiagClass(class1);
    m0_c1_f0 << MDiagClass(class1);
    m0_c1_f1 << MDiagClass(class1);
    m1_c1_f1 << MDiagClass(class1);

    m1_c0_f1 << MDiagFunction(function1);
    m0_c0_f1 << MDiagFunction(function1);
    m0_c1_f1 << MDiagFunction(function1);
    m1_c1_f1 << MDiagFunction(function1);

    m_Diags.push_back(&m0_c0_f0);
    m_Diags.push_back(&m1_c0_f0);
    m_Diags.push_back(&m2_c0_f0);
    m_Diags.push_back(&m1_c1_f0);
    m_Diags.push_back(&m0_c1_f0);
    m_Diags.push_back(&m1_c0_f1);
    m_Diags.push_back(&m0_c0_f1);
    m_Diags.push_back(&m0_c1_f1);
    m_Diags.push_back(&m1_c1_f1);


    NcbiCout << "Testing good format strings" << NcbiEndl;
    {
        int expects[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
        x_TestString( "", expects );
    }
    {
        int expects[] = { 0, 1, 0, 1, 0, 1, 0, 0, 1 };
        x_TestString( "module", expects );
    }
    {
        int expects[] = { 0, 1, 0, 1, 0, 1, 0, 0, 1 };
        x_TestString( "[Warning]module", expects );
    }

    {
        int expects[] = { 1, 0, 1, 0, 1, 0, 1, 1, 0 };
        x_TestString( "!module", expects );
    }
    {
        int expects[] = { 0, 1, 1, 1, 0, 1, 0, 0, 1 };
        x_TestString( "module foo", expects );
    }
    {
        int expects[] = { 1, 0, 0, 0, 1, 0, 1, 1, 0 };
        x_TestString( "?", expects );
    }
    {
        int expects[] = { 0, 0, 0, 1, 0, 0, 0, 0, 1 };
        x_TestString( "module::class", expects );
    }
    {
        int expects[] = { 1, 1, 1, 0, 1, 1, 1, 1, 0 };
        x_TestString( "!module::class", expects );
    }
    {
        int expects[] = { 0, 0, 0, 1, 1, 0, 0, 1, 1 };
        x_TestString( "::class", expects );
    }
    {
        int expects[] = { 0, 0, 0, 0, 1, 0, 0, 1, 0 };
        x_TestString( "?::class", expects );
    }
    {
        int expects[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 };
        x_TestString( "module::class::function", expects );
    }
    {
        int expects[] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 };
        x_TestString( "module::class::function()", expects );
    }
    {
        int expects[] = { 1, 1, 1, 1, 1, 1, 1, 1, 0 };
        x_TestString( "!module::class::function", expects );
    }
    {
        int expects[] = { 0, 0, 0, 0, 0, 1, 0, 0, 1 };
        x_TestString( "module::function()", expects );
    }
    {
        int expects[] = { 1, 1, 1, 1, 1, 0, 1, 1, 0 };
        x_TestString( "!module::function()", expects );
    }
    {
        int expects[] = { 0, 0, 0, 0, 0, 1, 1, 1, 1 };
        x_TestString( "function()", expects );
    }
    {
        int expects[] = { 0, 0, 0, 0, 0, 0, 1, 1, 0 };
        x_TestString( "?::function()", expects );
    }
    {
        int expects[] = { 0, 0, 0, 0, 0, 0, 0, 1, 1 };
        x_TestString( "::class::function()", expects );
    }
    {
        int expects[] = { 0, 0, 0, 0, 0, 1, 1, 0, 0 };
        x_TestString( "::?::function()", expects );
    }
    m_Diags.clear();
}
コード例 #2
0
void CTestDiagApp::x_PrintMessages(int         test_number,
                                   int         idx,
                                   const char* module,
                                   const char* nclass,
                                   const char* function)
{
    string location  = string(module) + "::" + nclass + "::" +
                       function + "()";
    string postmsg   = location + " in ERR_POST";
    string exceptmsg = location + " in the one level exception";
    string secondmsg = location + " in the two levels exception";

    if (idx == 0) {
        m_Messages[ TCase( test_number, 0 ) ] = postmsg;
        m_Messages[ TCase( test_number, 1 ) ] = exceptmsg;
        m_Messages[ TCase( test_number, 2 ) ] = secondmsg;
    }

    // ERR_POST
    ERR_POST(x_MakeMessage(postmsg, idx, TCase(test_number,0))
             << MDiagModule(module)
             << MDiagClass(nclass)
             << MDiagFunction(function));

    // one level exception
    try {
        NCBI_EXCEPTION_VAR(expt, CException, eUnknown, "exception");
        expt.SetModule(module);
        expt.SetClass(nclass);
        expt.SetFunction(function);
        NCBI_EXCEPTION_THROW(expt);
    }
    catch (const  CException& ex) {
        NCBI_REPORT_EXCEPTION(x_MakeMessage(exceptmsg,
                                            idx,
                                            TCase(test_number, 1)), ex);
    }


#if defined(NCBI_COMPILER_WORKSHOP)
# if NCBI_COMPILER_VERSION == 530 || NCBI_COMPILER_VERSION == 550
    // Workshop 5.3 and 5.5 have MT-unsafe throw. To avoid test failures
    // use mutex.
    DEFINE_STATIC_FAST_MUTEX(s_ThrowMutex);
    CFastMutexGuard guard(s_ThrowMutex);
# endif
#endif


    // two level exceptions
    try {
        try {
            NCBI_EXCEPTION_VAR(expt, CException, eUnknown, "exception1");
            expt.SetModule(module);
            expt.SetClass(nclass);
            expt.SetFunction(function);
            NCBI_EXCEPTION_THROW(expt);
        }
        catch (const  CException& ex) {
            NCBI_EXCEPTION_VAR_EX(e2, &ex, CException, eUnknown, "exception2");
            e2.SetModule(module);
            e2.SetClass(nclass);
            e2.SetFunction(function);
            NCBI_EXCEPTION_THROW(e2);
        }
    }
    catch (const  CException& ex) {
        NCBI_REPORT_EXCEPTION(x_MakeMessage(secondmsg,
                                            idx,
                                            TCase(test_number, 2)), ex);
    }
}