Skip to content

Commit ccaefed

Browse files
NoremosArtyom Abakumov
authored andcommitted
PR #8059 postfix: Store temp test file in temp directory (#8065)
Co-authored-by: Artyom Abakumov <artyom.abakumov@red-soft.ru>
1 parent 4ec8045 commit ccaefed

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

src/common/tests/StringTest.cpp

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "boost/test/unit_test.hpp"
22
#include "../common/classes/fb_string.h"
3-
3+
#include <filesystem>
44
#include <string_view>
55

66
using namespace Firebird;
@@ -478,35 +478,30 @@ BOOST_AUTO_TEST_CASE(SubstrTest)
478478

479479
BOOST_AUTO_TEST_CASE(LoadFromFileTest)
480480
{
481-
// Find the path of the file 'test.txt' to read from
482-
// The file in the same directory
483-
484-
string path = __FILE__;
485-
FB_SIZE_T pos = path.rfind('/');
486-
if (pos == string::npos)
487-
{
488-
pos = path.rfind('\\');
489-
if (pos == string::npos)
490-
{
491-
pos = 0;
492-
}
493-
else
494-
++pos;
495-
}
496-
else
497-
++pos;
498-
499-
path.resize(pos);
500-
path += "test.txt";
481+
namespace fs = std::filesystem;
482+
auto tempFilePath = fs::temp_directory_path() / "test.txt";
483+
const char* filename = tempFilePath.string().data();
484+
FILE *x = fopen(tempFilePath.string().data(), "w+");
485+
486+
std::string_view line1 = "char lbl[] = \"0123456789\";";
487+
std::string_view line2 = ""; // LoadFormFile read from '\n'
488+
std::string_view line3 = "//#define CHECK_FATAL_RANGE_EXCEPTION";
489+
490+
fwrite(line1.data(), 1, line1.length(), x);
491+
fwrite("\n", 1, 1, x);
492+
fwrite(line2.data(), 1, line2.length(), x);
493+
fwrite("\n", 1, 1, x);
494+
fwrite(line3.data(), 1, line3.length(), x);
495+
fclose(x);
501496

497+
x = fopen(filename, "r");
502498
string b;
503-
FILE *x = fopen(path.data(), "rt");
504499
b.LoadFromFile(x);
505-
validate(b, "char lbl[] = \"0123456789\";");
500+
validate(b, line1);
506501
b.LoadFromFile(x);
507-
validate(b, "");
502+
validate(b, line2);
508503
b.LoadFromFile(x);
509-
validate(b, "//#define CHECK_FATAL_RANGE_EXCEPTION");
504+
validate(b, line3);
510505
fclose(x);
511506
}
512507

0 commit comments

Comments
 (0)