How To Use
 All Modules Pages
C++ Example for main source file
// File: TestXmlCheckWithPugiXml.cpp
#include "stdafx.h"
//-----------------------------------------------------------------------------
// Configure usage of boost test
//-----------------------------------------------------------------------------
/// [boost.test configure]
// To write boost test cases within multiple source files
// define the name of your test module within exactly one cpp file
// and before including any boost test header.
// Do not define BOOST_TEST_MAIN. Otherwise you may get link errors
// like "init_unit_test_suite already defined"
#define BOOST_TEST_MODULE "Testing XmlCheck with PugiXml"
#include <boost/bind.hpp>
#include <boost/test/auto_unit_test.hpp>
// Use the boost auto link feature which automatically chooses the correct library version
#define BOOST_LIB_NAME boost_unit_test_framework
#include <boost/config/auto_link.hpp>
/// [boost.test configure]
//-----------------------------------------------------------------------------
// Add implementaion code of TestToolBox
//-----------------------------------------------------------------------------
/// [ttb include impl]
// directly include implementation code,
// possible configuration via preprocessor definitions within project settings
#include "TestToolBox\TestToolBoxImpl.h"
// Define name of this component for simple trace utility and set initial trace level
TTB_TRC_DEF_GLOBALS("TestXmlCheckWithPugiXmlc", TL_VAL_DEBUG);
namespace TTB = TestToolBox;
/// [ttb include impl]
//-----------------------------------------------------------------------------
// Other includes
//-----------------------------------------------------------------------------
#include "MyTestCommands.h"
#include <assert.h>
#include <iostream>
using namespace std;
//-----------------------------------------------------------------------------
// Global fixture
//-----------------------------------------------------------------------------
// Forward declaration
void InitialPreparation();
/// [boost.test global fixture impl]
// Global Fixture for onetime initialization and tear down.
// Base class DefaultSettingsForBoostAndTTB cares for proper initialization
// and cleanup of TestToolBox (e.g. test protocol files, recorded TestEvents)
struct MyGlobalSettingsForTestToolBox : public TTB::DefaultSettingsForBoostAndTTB
{
MyGlobalSettingsForTestToolBox(void)
{
// In case of using TTB::TestEvents you can specify your desired
// syntax for writing test events to protocol file.
// This may be useful when writing / correcting test cases because
// you can directly copy recorded test sequences from protocol file
// to your source code.
// When defining via command line the needed check macro as prefix
// (e.g. "-prefixEvents TTB_EXP") you get the ready to copy format
// in C++ syntax (TTB_EXP("Some event generated");).
// If prefix string is not set the simple and more readable prefix
// ">" is used.
std::string prefixForTestEventsWithinOutFile =
TTB::TheEnvironment()->GetCommandLineOption("-prefixEvents");
bool detailedLog = true;
TTB::TestEvents::Get()->SetDetailedLog(
detailedLog, prefixForTestEventsWithinOutFile);
// Specific preparations
// e.g. generate test data, startup system under test,
// execute initial test cases to be performed directly after startup
InitialPreparation();
}
// Define your specific destructor if you have to perform special cleanup
// at end of testing (e.g. shutdown test environment)
};
/// [boost.test global fixture impl]
/// [boost.test global fixture install]
// Install your specific class MyGlobalSettingsForTestToolBox
// as a global fixture for boost
BOOST_GLOBAL_FIXTURE(MyGlobalSettingsForTestToolBox);
/// [boost.test global fixture install]
//-----------------------------------------------------------------------------
// Regular boost test case not visible within TestToolBox
BOOST_AUTO_TEST_CASE(EmptyTestcaseToShowOriginalBoostTestCase)
{
/// [boost.test TTB_OUT_S]
// Illustrate usage of macros TTB_OUT_S and TTTB_T_OUT_S
bool someCondition = false;
double pi = 3.14159265359;
// Macro TTB_OUT_S writes informational messages to one or more of the
// targets .out, .rpt, stdout. The calls do not affect test results!
TTB_OUT_S("This macro supports stream syntax x=" << std::setprecision(4) << pi
<< " condition=" << std::boolalpha << someCondition);
TTB_OUT_S("With default settings the output goes to .out + .rpt + stdout");
// Change target for TTB_OUT_S
TTB::TheProtocol()->SelectTargetsForOutS(TTB::OutputMode::M_STDOUT);
TTB_OUT_S("After change of default settings this message goes only to stdout");
// You can select multiple targets
TTB::TheProtocol()->SelectTargetsForOutS(TTB::OutputMode::M_STDOUT | TTB::OutputMode::M_OUTFILE);
TTB_OUT_S("After another change of settings this message goes to .out + stdout");
// Explicitly specify target for a single message
TTB_T_OUT_S(TTB::OutputMode::M_STDOUT, "This message with explicit target goes to stdout");
TTB_T_OUT_S(TTB::OutputMode::M_OUTFILE| TTB::OutputMode::M_RPTFILE,
"This message with explicit targets goes to .out + .rpt");
// Switching off output of TTB_OUT_S:
// As default class Protocol produces output for messages up to verbosity eREGULAR.
// By changing verbosity of macro TTB_OUT_S from its default eREGULAR to eVERBOUS
// the output through TTB_OUT_S can be switched off completely.
TTB::TheProtocol()->SetVerbosityForOutS(TTB::OutputLevel::eVERBOUS);
TTB::TheProtocol()->SelectTargetsForOutS(TTB::OutputMode::M_STDOUT | TTB::OutputMode::M_OUTFILE | TTB::OutputMode::M_RPTFILE);
TTB_OUT_S("This verbous message goes to nowhere");
TTB::TheProtocol()->SetVerbosityForOutS(TTB::OutputLevel::eREGULAR);
TTB_OUT_S("And this regular message goes to out + rpt + stdout");
/// [boost.test TTB_OUT_S]
// TODO: Add Dump method within Protocol
}
//-----------------------------------------------------------------------------