1+
2+ /* *
3+ * @file SerializationFileAccessTest.cpp
4+ *
5+ * @brief This file contains the unit test to check if serialization file can
6+ * be accessed before the simulation starts, using GTest.
7+ *
8+ * @ingroup Testing/UnitTesting
9+ */
10+
11+ #include " Core.h"
12+ #include " gtest/gtest.h"
13+ #include < filesystem>
14+ #include < fstream>
15+ #include < iostream>
16+ #include < tinyxml.h>
17+
18+ using namespace std ;
19+
20+ // Test case for isSerializedFileWritable function
21+ TEST (SerializationFileAccessTest, FileWritableTest)
22+ {
23+ string executable = " ./cgraphitti" ;
24+ string configFile = " ../configfiles/test-small-connected.xml" ;
25+ string nonWritableFilePath = " /root/non_writable_file.txt" ;
26+ string nonWritableArgument = " -c " + configFile + " -w " + nonWritableFilePath;
27+
28+ Core core;
29+
30+ // Test a non-writable file
31+ ASSERT_EQ (-1 , core.runSimulation (executable, nonWritableArgument));
32+ }
33+
34+ // Optional: create a similar test file to test a a positive case
35+ // 1. Create a writable file
36+ // string writableFilePath = "writable_file.txt";
37+ // string writableArgument = "-c " + configFile + " -w " + writableFilePath;
38+ // std::ofstream writableFile(writableFilePath);
39+ // writableFile.close();
40+ // 2. Test
41+ // ASSERT_EQ(0, core.runSimulation(executable, writableArgument));
42+ // 3. Clean up the writable file
43+ // std::filesystem::remove(writableFilePath);
0 commit comments