guint len = json_array_get_length(json_arr);
for (guint i = 0; i < len; ++i) {
auto* val = json_array_get_string_element(json_arr, i);
+ if (val == nullptr)
+ val = "";
+
auto* p = reinterpret_cast<unsigned char*>(const_cast<char*>(val));
std::vector<unsigned char> value;
std::copy(p, p + (strlen(val) + 1), std::back_inserter(value));
} else {
auto* val = json_node_get_string(node);
if (val == nullptr)
- return;
+ val = "";
+
auto* p = reinterpret_cast<unsigned char*>(const_cast<char*>(val));
std::vector<unsigned char> value;
std::copy(p, p + (strlen(val) + 1), std::back_inserter(value));
ASSERT_EQ(std::string(val_array[1]), "VALUE1");
}
+TEST_F(BundleTest, bundle_from_json_2) {
+ const char json[] = "{\"KEY1\":0,\"KEY2\":[0]}";
+ bundle* json_b = nullptr;
+ int ret = bundle_from_json(json, &json_b);
+ std::unique_ptr<bundle, decltype(bundle_free)*> b_ptr(json_b, bundle_free);
+ ASSERT_EQ(ret, BUNDLE_ERROR_NONE);
+
+ const char* val = bundle_get_val(json_b, "KEY1");
+ ASSERT_EQ(get_last_result(), BUNDLE_ERROR_NONE);
+ ASSERT_EQ(std::string(val), "");
+
+ int len = 0;
+ const char** val_array = bundle_get_str_array(json_b, "KEY2", &len);
+ ASSERT_EQ(get_last_result(), BUNDLE_ERROR_NONE);
+ ASSERT_NE(val_array, nullptr);
+ ASSERT_NE(len, 0);
+ ASSERT_EQ(std::string(val_array[0]), "");
+}
+
TEST_F(BundleTest, bundle_from_json_N) {
int ret = bundle_from_json(nullptr, nullptr);
ASSERT_EQ(ret, BUNDLE_ERROR_INVALID_PARAMETER);