| 1 | // |
|---|---|
| 2 | // NDCTest.cpp |
| 3 | // |
| 4 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
| 5 | // and Contributors. |
| 6 | // |
| 7 | // SPDX-License-Identifier: BSL-1.0 |
| 8 | // |
| 9 | |
| 10 | |
| 11 | #include "NDCTest.h" |
| 12 | #include "Poco/CppUnit/TestCaller.h" |
| 13 | #include "Poco/CppUnit/TestSuite.h" |
| 14 | #include "Poco/NestedDiagnosticContext.h" |
| 15 | #include <iostream> |
| 16 | |
| 17 | |
| 18 | using Poco::NDC; |
| 19 | |
| 20 | |
| 21 | NDCTest::NDCTest(const std::string& rName): CppUnit::TestCase(rName) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | |
| 26 | NDCTest::~NDCTest() |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | |
| 31 | void NDCTest::testNDC() |
| 32 | { |
| 33 | NDC ndc; |
| 34 | assertTrue (ndc.depth() == 0); |
| 35 | ndc.push("item1"); |
| 36 | assertTrue (ndc.toString() == "item1"); |
| 37 | assertTrue (ndc.depth() == 1); |
| 38 | ndc.push("item2"); |
| 39 | assertTrue (ndc.toString() == "item1:item2"); |
| 40 | assertTrue (ndc.depth() == 2); |
| 41 | ndc.pop(); |
| 42 | assertTrue (ndc.depth() == 1); |
| 43 | assertTrue (ndc.toString() == "item1"); |
| 44 | ndc.pop(); |
| 45 | assertTrue (ndc.depth() == 0); |
| 46 | } |
| 47 | |
| 48 | |
| 49 | void NDCTest::testNDCScope() |
| 50 | { |
| 51 | poco_ndc("item1"); |
| 52 | assertTrue (NDC::current().depth() == 1); |
| 53 | { |
| 54 | poco_ndc("item2"); |
| 55 | assertTrue (NDC::current().depth() == 2); |
| 56 | { |
| 57 | poco_ndc("item3"); |
| 58 | assertTrue (NDC::current().depth() == 3); |
| 59 | NDC::current().dump(std::cout); |
| 60 | } |
| 61 | assertTrue (NDC::current().depth() == 2); |
| 62 | } |
| 63 | assertTrue (NDC::current().depth() == 1); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | void NDCTest::setUp() |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | |
| 72 | void NDCTest::tearDown() |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | |
| 77 | CppUnit::Test* NDCTest::suite() |
| 78 | { |
| 79 | CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NDCTest"); |
| 80 | |
| 81 | CppUnit_addTest(pSuite, NDCTest, testNDC); |
| 82 | CppUnit_addTest(pSuite, NDCTest, testNDCScope); |
| 83 | |
| 84 | return pSuite; |
| 85 | } |
| 86 |