-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve error message when load model failed (#1533)
* fix: error for models start * fix: add unit tests --------- Co-authored-by: vansangpfiev <[email protected]>
- Loading branch information
1 parent
0fd3c62
commit c434ac2
Showing
5 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <gtest/gtest.h> | ||
#include <json/json.h> | ||
#include <string> | ||
#include "utils/json_helper.h" | ||
|
||
// Test Suite | ||
TEST(ParseJsonStringTest, ValidJsonObject) { | ||
std::string json_str = R"({"name": "John", "age": 30})"; | ||
Json::Value result = json_helper::ParseJsonString(json_str); | ||
|
||
EXPECT_EQ(result["name"].asString(), "John"); | ||
EXPECT_EQ(result["age"].asInt(), 30); | ||
} | ||
|
||
TEST(ParseJsonStringTest, ValidJsonArray) { | ||
std::string json_str = R"([1, 2, 3, 4, 5])"; | ||
Json::Value result = json_helper::ParseJsonString(json_str); | ||
|
||
EXPECT_EQ(result.size(), 5); | ||
EXPECT_EQ(result[0].asInt(), 1); | ||
} | ||
|
||
TEST(ParseJsonStringTest, InvalidJson) { | ||
std::string json_str = R"({"name": "John", "age": )"; | ||
Json::Value result = json_helper::ParseJsonString(json_str); | ||
|
||
EXPECT_TRUE(result["age"].isNull()); | ||
} | ||
|
||
TEST(ParseJsonStringTest, EmptyString) { | ||
std::string json_str = ""; | ||
Json::Value result = json_helper::ParseJsonString(json_str); | ||
|
||
EXPECT_TRUE(result.isNull()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
#include <json/json.h> | ||
#include <string> | ||
namespace json_helper { | ||
inline Json::Value ParseJsonString(const std::string& json_str) { | ||
Json::Value root; | ||
Json::Reader reader; | ||
reader.parse(json_str, root); | ||
return root; | ||
} | ||
} |