mirror of
https://github.com/nlohmann/json
synced 2025-01-09 00:40:14 +00:00
refactor unit test in case of throw, the fclose will not be called. using unique_ptr with custom destructor will ensure that
This commit is contained in:
parent
91ff96a737
commit
a794cfdba3
@ -386,42 +386,37 @@ TEST_CASE("json.org examples")
|
||||
}
|
||||
SECTION("FILE 1.json")
|
||||
{
|
||||
auto f = fopen("test/data/json.org/1.json", "r");
|
||||
std::unique_ptr<FILE, decltype(&fclose)> f(fopen("test/data/json.org/1.json", "r"), &fclose);
|
||||
json j;
|
||||
CHECK_NOTHROW(j.parse(f));
|
||||
fclose(f);
|
||||
CHECK_NOTHROW(j.parse(f.get()));
|
||||
}
|
||||
|
||||
SECTION("FILE 2.json")
|
||||
{
|
||||
auto f = fopen("test/data/json.org/2.json", "r");
|
||||
std::unique_ptr<FILE, decltype(&fclose)> f(fopen("test/data/json.org/2.json", "r"), &fclose);
|
||||
json j;
|
||||
CHECK_NOTHROW(j.parse(f));
|
||||
fclose(f);
|
||||
CHECK_NOTHROW(j.parse(f.get()));
|
||||
}
|
||||
|
||||
SECTION("FILE 3.json")
|
||||
{
|
||||
auto f = fopen("test/data/json.org/3.json", "r");
|
||||
std::unique_ptr<FILE, decltype(&fclose)> f(fopen("test/data/json.org/3.json", "r"), &fclose);
|
||||
json j;
|
||||
CHECK_NOTHROW(j.parse(f));
|
||||
fclose(f);
|
||||
CHECK_NOTHROW(j.parse(f.get()));
|
||||
}
|
||||
|
||||
SECTION("FILE 4.json")
|
||||
{
|
||||
auto f = fopen("test/data/json.org/4.json", "r");
|
||||
std::unique_ptr<FILE, decltype(&fclose)> f(fopen("test/data/json.org/4.json", "r"), &fclose);
|
||||
json j;
|
||||
CHECK_NOTHROW(j.parse(f));
|
||||
fclose(f);
|
||||
CHECK_NOTHROW(j.parse(f.get()));
|
||||
}
|
||||
|
||||
SECTION("FILE 5.json")
|
||||
{
|
||||
auto f = fopen("test/data/json.org/5.json", "r");
|
||||
std::unique_ptr<FILE, decltype(&fclose)> f(fopen("test/data/json.org/5.json", "r"), &fclose);
|
||||
json j;
|
||||
CHECK_NOTHROW(j.parse(f));
|
||||
fclose(f);
|
||||
CHECK_NOTHROW(j.parse(f.get()));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user