2121#include " errorlogger.h"
2222#include " filesettings.h"
2323#include " fixture.h"
24+ #include " helpers.h"
2425#include " standards.h"
2526
27+ #include < fstream>
2628#include < list>
29+ #include < set>
2730#include < sstream>
31+ #include < string>
2832
2933#include " xml.h"
3034
@@ -45,6 +49,7 @@ class TestAnalyzerInformation : public TestFixture {
4549 TEST_CASE (filesTextDuplicateFile);
4650 TEST_CASE (parse);
4751 TEST_CASE (skipAnalysis);
52+ TEST_CASE (loadFileOpenForWriting);
4853 }
4954
5055 void getAnalyzerInfoFileFromFilesTxt () const {
@@ -309,6 +314,35 @@ class TestAnalyzerInformation : public TestFixture {
309314 ASSERT_EQUALS (0 , errorList.size ());
310315 }
311316 }
317+
318+ void loadFileOpenForWriting () const {
319+ const std::string buildDir = " testanalyzerinfo-builddir" ;
320+ const ScopedFile file (" file1.c.analyzerinfo" ,
321+ " <?xml version=\" 1.0\" ?>\n "
322+ " <analyzerinfo>\n "
323+ " <includes>\n "
324+ " <filename>file1.h</filename>\n "
325+ " </includes>\n "
326+ " <hash>123</hash>\n "
327+ " </analyzerinfo>\n " ,
328+ buildDir);
329+
330+ std::ofstream writer (file.path (), std::ios::app);
331+ ASSERT (writer.is_open ());
332+
333+ {
334+ const AnalyzerInformation analyzerInfo;
335+ const std::set<std::string> includes = analyzerInfo.getIncludes (buildDir, " file1.c" , " " , 0 );
336+ ASSERT_EQUALS (1 , includes.size ());
337+ ASSERT_EQUALS (" file1.h" , *includes.cbegin ());
338+ }
339+ {
340+ AnalyzerInformation analyzerInfo;
341+ std::list<ErrorMessage> errorList;
342+ ASSERT_EQUALS (false , analyzerInfo.analyzeFile (buildDir, " file1.c" , " " , 0 , 123 , errorList));
343+ ASSERT_EQUALS (0 , errorList.size ());
344+ }
345+ }
312346};
313347
314348REGISTER_TEST (TestAnalyzerInformation)
0 commit comments