Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR #8059 postfix: Store temp test file in temp directory #8065

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 20 additions & 25 deletions src/common/tests/StringTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "boost/test/unit_test.hpp"
#include "../common/classes/fb_string.h"

#include <filesystem>
#include <string_view>

using namespace Firebird;
Expand Down Expand Up @@ -478,35 +478,30 @@ BOOST_AUTO_TEST_CASE(SubstrTest)

BOOST_AUTO_TEST_CASE(LoadFromFileTest)
{
// Find the path of the file 'test.txt' to read from
// The file in the same directory

string path = __FILE__;
FB_SIZE_T pos = path.rfind('/');
if (pos == string::npos)
{
pos = path.rfind('\\');
if (pos == string::npos)
{
pos = 0;
}
else
++pos;
}
else
++pos;

path.resize(pos);
path += "test.txt";
namespace fs = std::filesystem;
auto tempFilePath = fs::temp_directory_path() / "test.txt";
const char* filename = tempFilePath.string().data();
FILE *x = fopen(tempFilePath.string().data(), "w+");

std::string_view line1 = "char lbl[] = \"0123456789\";";
std::string_view line2 = ""; // LoadFormFile read from '\n'
std::string_view line3 = "//#define CHECK_FATAL_RANGE_EXCEPTION";

fwrite(line1.data(), 1, line1.length(), x);
fwrite("\n", 1, 1, x);
fwrite(line2.data(), 1, line2.length(), x);
fwrite("\n", 1, 1, x);
fwrite(line3.data(), 1, line3.length(), x);
fclose(x);

x = fopen(filename, "r");
string b;
FILE *x = fopen(path.data(), "rt");
b.LoadFromFile(x);
validate(b, "char lbl[] = \"0123456789\";");
validate(b, line1);
b.LoadFromFile(x);
validate(b, "");
validate(b, line2);
b.LoadFromFile(x);
validate(b, "//#define CHECK_FATAL_RANGE_EXCEPTION");
validate(b, line3);
fclose(x);
}

Expand Down
Loading