| 36 | #include "twtest/test.h" |
| 37 | |
| 38 | void TestDebug() |
| 39 | { |
| 40 | // it is amusing that we use cDebug to output the results of testing cDebug |
| 41 | // "Are you insane?" ... "No, I am not." |
| 42 | cDebug d("TestDebug()"); |
| 43 | d.TraceDebug("Entering..."); |
| 44 | |
| 45 | // save the current debug level, since we will be altering it. |
| 46 | int oldDebugLevel = cDebug::GetDebugLevel(); |
| 47 | |
| 48 | // test debug level variation... |
| 49 | d.TraceDebug("Setting debug level to Debug(%d)\n", cDebug::D_DEBUG); |
| 50 | cDebug::SetDebugLevel(cDebug::D_DEBUG); |
| 51 | d.TraceDebug("You should see this, as well as line 2 below, but not line 3.\n"); |
| 52 | d.TraceWarning("Line 2: Warning(%d)\n", cDebug::D_WARNING); |
| 53 | d.TraceDetail("Line 3: Detail(%d)\n", cDebug::D_DETAIL); |
| 54 | d.TraceDebug("Restoring the debug level to %d\n", oldDebugLevel); |
| 55 | cDebug::SetDebugLevel(oldDebugLevel); |
| 56 | |
| 57 | // testing the output source |
| 58 | int oldOutTarget = 0; |
| 59 | if (cDebug::HasOutTarget(cDebug::OUT_STDOUT)) |
| 60 | oldOutTarget |= cDebug::OUT_STDOUT; |
| 61 | if (cDebug::HasOutTarget(cDebug::OUT_TRACE)) |
| 62 | oldOutTarget |= cDebug::OUT_TRACE; |
| 63 | if (cDebug::HasOutTarget(cDebug::OUT_FILE)) |
| 64 | oldOutTarget |= cDebug::OUT_FILE; |
| 65 | cDebug::RemoveOutTarget(cDebug::OUT_STDOUT); |
| 66 | cDebug::RemoveOutTarget(cDebug::OUT_TRACE); |
| 67 | cDebug::RemoveOutTarget(cDebug::OUT_FILE); |
| 68 | |
| 69 | d.TraceDebug("You should not see this (All out targets removed)\n"); |
| 70 | cDebug::AddOutTarget(cDebug::OUT_STDOUT); |
| 71 | d.TraceDebug("You should see this in stdout only.\n"); |
| 72 | cDebug::AddOutTarget(cDebug::OUT_TRACE); |
| 73 | d.TraceDebug("You should see this in stdout and trace.\n"); |
| 74 | cDebug::RemoveOutTarget(cDebug::OUT_STDOUT); |
| 75 | d.TraceDebug("You should see this in trace only.\n"); |
| 76 | |
| 77 | |
| 78 | // set up an output file...use the temp file in test.h |
| 79 | std::string str = TwTestPath("debug.out"); |
| 80 | |
| 81 | #ifdef DEBUG |
| 82 | TEST(cDebug::SetOutputFile(str.c_str())); |
| 83 | #endif |
| 84 | |
| 85 | d.TraceDebug("This should be in trace and the file %s.\n", str.c_str()); |
| 86 | |
| 87 | // restore the out source... |
| 88 | // TODO -- note that the original output file cannot be restored; this sucks! |
| 89 | if (oldOutTarget & cDebug::OUT_STDOUT) |
| 90 | cDebug::AddOutTarget(cDebug::OUT_STDOUT); |
| 91 | else |
| 92 | cDebug::RemoveOutTarget(cDebug::OUT_STDOUT); |
| 93 | if (oldOutTarget & cDebug::OUT_TRACE) |
| 94 | cDebug::AddOutTarget(cDebug::OUT_TRACE); |
| 95 | else |
nothing calls this directly
no test coverage detected