|
1 | 1 | #include "boost/test/unit_test.hpp"
|
2 | 2 | #include "../common/classes/fb_string.h"
|
3 |
| - |
| 3 | +#include <filesystem> |
4 | 4 | #include <string_view>
|
5 | 5 |
|
6 | 6 | using namespace Firebird;
|
@@ -478,35 +478,30 @@ BOOST_AUTO_TEST_CASE(SubstrTest)
|
478 | 478 |
|
479 | 479 | BOOST_AUTO_TEST_CASE(LoadFromFileTest)
|
480 | 480 | {
|
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); |
501 | 496 |
|
| 497 | + x = fopen(filename, "r"); |
502 | 498 | string b;
|
503 |
| - FILE *x = fopen(path.data(), "rt"); |
504 | 499 | b.LoadFromFile(x);
|
505 |
| - validate(b, "char lbl[] = \"0123456789\";"); |
| 500 | + validate(b, line1); |
506 | 501 | b.LoadFromFile(x);
|
507 |
| - validate(b, ""); |
| 502 | + validate(b, line2); |
508 | 503 | b.LoadFromFile(x);
|
509 |
| - validate(b, "//#define CHECK_FATAL_RANGE_EXCEPTION"); |
| 504 | + validate(b, line3); |
510 | 505 | fclose(x);
|
511 | 506 | }
|
512 | 507 |
|
|
0 commit comments