Skip to content

Commit 088bdbb

Browse files
author
Divya Kamath
committed
Restore serialFileAccessTest
1 parent 7a50b56 commit 088bdbb

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ tests
4545
serialFullTest
4646
serialFirstHalfTest
4747
serialSecondHalfTest
48+
serialFileAccessTest
4849
core
4950
# core is generated by GDB during debugging
5051

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)