1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestXMLDisplayOutputWindow.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #include "vtkXMLFileOutputWindow.h"
16 
17 #include "vtkSmartPointer.h"
18 #include <string>
19 
TestXMLFileOutputWindow(int argc,char * argv[])20 int TestXMLFileOutputWindow(int argc,char *argv[])
21 {
22   if (argc < 2)
23     {
24     std::cout << "Usage: " << argv[0] << " outputFilename" << std::endl;
25     return EXIT_FAILURE;
26     }
27   std::string sample("Test string: &\"'<>");
28 
29   {
30   vtkSmartPointer<vtkXMLFileOutputWindow> ofw =
31     vtkSmartPointer<vtkXMLFileOutputWindow>::New();
32   ofw->SetInstance(ofw);
33   ofw->FlushOn();
34 
35   // Use the default filename
36   ofw->DisplayTag(sample.c_str());
37   ofw->DisplayText(sample.c_str());
38   ofw->DisplayErrorText(sample.c_str());
39   ofw->DisplayWarningText(sample.c_str());
40   ofw->DisplayGenericWarningText(sample.c_str());
41   ofw->DisplayDebugText(sample.c_str());
42 
43   // Check NULL strings
44   ofw->DisplayTag(NULL);
45   ofw->DisplayText(NULL);
46   ofw->DisplayErrorText(NULL);
47   ofw->DisplayWarningText(NULL);
48   ofw->DisplayGenericWarningText(NULL);
49   ofw->DisplayDebugText(NULL);
50   }
51 
52   // Append to default
53   {
54   vtkSmartPointer<vtkXMLFileOutputWindow> ofw2 =
55     vtkSmartPointer<vtkXMLFileOutputWindow>::New();
56   ofw2->SetInstance(ofw2);
57   ofw2->AppendOn();
58   ofw2->DisplayText("Appended");
59   }
60 
61   // Change the file name
62   {
63   vtkSmartPointer<vtkXMLFileOutputWindow> ofw3 =
64     vtkSmartPointer<vtkXMLFileOutputWindow>::New();
65   ofw3->SetInstance(ofw3);
66   ofw3->SetFileName(argv[1]);
67   ofw3->DisplayTag(sample.c_str());
68   ofw3->DisplayText(sample.c_str());
69   ofw3->DisplayErrorText(sample.c_str());
70   ofw3->DisplayWarningText(sample.c_str());
71   ofw3->DisplayGenericWarningText(sample.c_str());
72   ofw3->DisplayDebugText(sample.c_str());
73   ofw3->AppendOn();
74   ofw3->DisplayText("Appended");
75   }
76 
77   // Now, compare the default and specified files
78   // Read the default XML file
79   std::ifstream dfin("vtkMessageLog.xml");
80   std::string def((std::istreambuf_iterator<char>(dfin)),
81                   std::istreambuf_iterator<char>());
82 
83   if (dfin.fail())
84     {
85     std::cout << argv[0] << ": Cannot open vtkMessageLog.xml" << std::endl;
86     return EXIT_FAILURE;
87     }
88 
89   std::ifstream sfin(argv[1]);
90   std::string specified((std::istreambuf_iterator<char>(sfin)),
91                         std::istreambuf_iterator<char>());
92 
93   if (sfin.fail())
94     {
95     std::cout << argv[0] << ": Cannot open " << argv[1] << std::endl;
96     return EXIT_FAILURE;
97     }
98 
99   if (def != specified)
100     {
101     std::cout << "The string in the default file ***********" << std::endl
102               << def << std::endl
103               << "does not match the string in the specified file  ***********" << std::endl
104               << specified << std::endl;
105     return EXIT_FAILURE;
106     }
107 
108   return EXIT_SUCCESS;
109 }
110