|
Boost-Commit : |
From: john.groups_at_[hidden]
Date: 2008-01-09 09:52:20
Author: jtorjo
Date: 2008-01-09 09:52:19 EST (Wed, 09 Jan 2008)
New Revision: 42638
URL: http://svn.boost.org/trac/boost/changeset/42638
Log:
[logging]
- added test for formatter::file
Added:
sandbox/logging/lib/logging/tests/test_file/
sandbox/logging/lib/logging/tests/test_file/test.cpp (contents, props changed)
sandbox/logging/lib/logging/tests/test_file/test.vcproj (contents, props changed)
sandbox/logging/lib/logging/tests/test_file/test_file.sln (contents, props changed)
sandbox/logging/lib/logging/tests/test_rolling_file/
sandbox/logging/lib/logging/tests/test_rolling_file/test.cpp (contents, props changed)
sandbox/logging/lib/logging/tests/test_rolling_file/test.sln (contents, props changed)
sandbox/logging/lib/logging/tests/test_rolling_file/test.vcproj (contents, props changed)
Properties modified:
sandbox/logging/lib/logging/tests/ (props changed)
Added: sandbox/logging/lib/logging/tests/test_file/test.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/test_file/test.cpp 2008-01-09 09:52:19 EST (Wed, 09 Jan 2008)
@@ -0,0 +1,94 @@
+
+/*
+ Tests formatter::file
+*/
+
+#include <boost/logging/format.hpp>
+#include <boost/logging/writer/ts_write.hpp>
+#include <string>
+
+using namespace boost::logging;
+
+typedef logger_format_write< > log_type;
+
+BOOST_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts )
+BOOST_DEFINE_LOG(g_l, log_type)
+
+#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l, g_log_filter->is_enabled() )
+
+
+void write_to_clean_file() {
+ // first, write to a clean file (that is, don't append to it)
+ g_l->writer().add_destination( destination::file("out.txt", destination::file_settings().initial_overwrite(true) ));
+ g_l->writer().add_formatter( formatter::append_newline_if_needed() );
+ g_l->writer().add_destination( destination::cout() );
+ g_l->turn_cache_off();
+
+ // read this .cpp file - every other line is logged (odd lines)
+ std::ifstream in("test.cpp");
+ bool enabled = true;
+ std::string line;
+ while ( std::getline(in, line) ) {
+ g_log_filter->set_enabled(enabled);
+ L_ << "line odd " << line;
+ enabled = !enabled;
+ }
+}
+
+void append_to_file() {
+ // second, append to the same file
+
+ // ... first, remove old destination
+ g_l->writer().del_destination( destination::file("out.txt"));
+ // ... now, re-add the same file - but now, for appending
+ g_l->writer().add_destination( destination::file("out.txt",
+ destination::file_settings().initial_overwrite(false).do_append(true) ));
+
+ // read this .cpp file - every other line is logged (even lines now)
+ std::ifstream in("test.cpp");
+ bool enabled = false;
+ std::string line;
+ while ( std::getline(in, line) ) {
+ g_log_filter->set_enabled(enabled);
+ L_ << "line even " << line;
+ enabled = !enabled;
+ }
+
+ g_l->writer().del_destination( destination::file("out.txt"));
+ g_log_filter->set_enabled(true);
+ L_ << "should not be written to file, only to console";
+}
+
+// now, see that what we've written was ok
+void test_write_ok() {
+ std::ifstream test("test.cpp");
+ std::ifstream out("out.txt");
+ std::string test_line, out_line;
+ // first, odd lines
+ while ( std::getline(test, test_line) ) {
+ std::getline(out, out_line);
+ BOOST_ASSERT( "line odd " + test_line == out_line );
+ std::getline(test, test_line); // ignore even line
+ }
+
+ test.close();
+ std::ifstream test2("test.cpp");
+
+ // second, even lines
+ while ( std::getline(test2, test_line) && std::getline(test2, test_line) ) {
+ std::getline(out, out_line);
+ BOOST_ASSERT( "line even " + test_line == out_line );
+ }
+
+ // out.txt - should have no more lines
+ std::getline(out, out_line);
+ BOOST_ASSERT( out_line.empty() );
+}
+
+
+int main() {
+ write_to_clean_file();
+ append_to_file();
+ test_write_ok();
+}
+
Added: sandbox/logging/lib/logging/tests/test_file/test.vcproj
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/test_file/test.vcproj 2008-01-09 09:52:19 EST (Wed, 09 Jan 2008)
@@ -0,0 +1,181 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="test_file"
+ ProjectGUID="{C5897099-5FA2-4E12-AFFC-2015364347FA}"
+ RootNamespace="test"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=".,../../../.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ AdditionalLibraryDirectories="D:\boosts\boost_1_33_1\bin\boost\libs\thread\build\libboost_thread.lib\vc-8_0\debug\threading-multi"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath=".\test.cpp"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Added: sandbox/logging/lib/logging/tests/test_file/test_file.sln
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/test_file/test_file.sln 2008-01-09 09:52:19 EST (Wed, 09 Jan 2008)
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcproj", "{C5897099-5FA2-4E12-AFFC-2015364347FA}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {C5897099-5FA2-4E12-AFFC-2015364347FA}.Debug|Win32.ActiveCfg = Debug|Win32
+ {C5897099-5FA2-4E12-AFFC-2015364347FA}.Debug|Win32.Build.0 = Debug|Win32
+ {C5897099-5FA2-4E12-AFFC-2015364347FA}.Release|Win32.ActiveCfg = Release|Win32
+ {C5897099-5FA2-4E12-AFFC-2015364347FA}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Added: sandbox/logging/lib/logging/tests/test_rolling_file/test.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/test_rolling_file/test.cpp 2008-01-09 09:52:19 EST (Wed, 09 Jan 2008)
@@ -0,0 +1,8 @@
+/*
+ Tests ...
+*/
+
+#include <boost/logging/logging.hpp>
+
+int main() {
+}
Added: sandbox/logging/lib/logging/tests/test_rolling_file/test.sln
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/test_rolling_file/test.sln 2008-01-09 09:52:19 EST (Wed, 09 Jan 2008)
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcproj", "{C5897099-5FA2-4E12-AFFC-2015364347FA}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {C5897099-5FA2-4E12-AFFC-2015364347FA}.Debug|Win32.ActiveCfg = Debug|Win32
+ {C5897099-5FA2-4E12-AFFC-2015364347FA}.Debug|Win32.Build.0 = Debug|Win32
+ {C5897099-5FA2-4E12-AFFC-2015364347FA}.Release|Win32.ActiveCfg = Release|Win32
+ {C5897099-5FA2-4E12-AFFC-2015364347FA}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Added: sandbox/logging/lib/logging/tests/test_rolling_file/test.vcproj
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/test_rolling_file/test.vcproj 2008-01-09 09:52:19 EST (Wed, 09 Jan 2008)
@@ -0,0 +1,181 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="test"
+ ProjectGUID="{C5897099-5FA2-4E12-AFFC-2015364347FA}"
+ RootNamespace="test"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=".,../../../.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ AdditionalLibraryDirectories="D:\boosts\boost_1_33_1\bin\boost\libs\thread\build\libboost_thread.lib\vc-8_0\debug\threading-multi"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath=".\test.cpp"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk