@@ -54,55 +54,30 @@ CHIP_ERROR SetupReader()
54
54
55
55
bool Matches (const char * referenceString, Json::Value & generatedValue)
56
56
{
57
- Json::StyledWriter writer;
58
57
auto generatedStr = JsonToString (generatedValue);
59
58
60
- auto matches = (generatedStr == std::string (referenceString));
59
+ // Normalize the reference string to the expected compact value.
60
+ Json::Reader reader;
61
+ Json::Value referenceValue;
62
+ reader.parse (referenceString, referenceValue);
63
+
64
+ Json::FastWriter writer;
65
+ writer.omitEndingLineFeed ();
66
+ auto compactReferenceString = writer.write (referenceValue);
67
+
68
+ auto matches = (generatedStr == compactReferenceString);
61
69
62
70
if (!matches)
63
71
{
64
72
printf (" Didn't match!\n " );
65
73
printf (" Reference:\n " );
66
- printf (" %s\n " , referenceString );
74
+ printf (" %s\n " , compactReferenceString. c_str () );
67
75
68
76
printf (" Generated:\n " );
69
77
printf (" %s\n " , generatedStr.c_str ());
70
78
}
71
79
72
80
return matches;
73
-
74
- #if 0
75
- //
76
- // Converting the reference string to a JSON representation and comparing
77
- // that against the generated JSON object would have been preferable. This avoids
78
- // the need to have reference strings expressed precisely to match the generated string
79
- // from the JSON converter, right down to the number of spaces,etc. This would have made
80
- // the reference string less britle and coupled to the jsoncpp converter implementation.
81
- //
82
- // However, jsoncpp converter converts positive values in the JSON to a signed
83
- // integer C type. This results in a mis-match with the generated JSON objects
84
- // that are created from spec-compliant TLV that correctly represents them as unsigned
85
- // integers in the JSON object.
86
- //
87
- // This mismatch nullifies this approach unfortunately.
88
- //
89
- // TODO: Investigate a way to compare using JSON objects.
90
- //
91
- Json::Reader reader;
92
- Json::Value referenceValue;
93
-
94
- bool ret = reader.parse(referenceString, referenceValue);
95
- if (ret != true) {
96
- return ret;
97
- }
98
-
99
- std::cout << generatedValue << "\n";
100
- std::cout << referenceValue << "\n";
101
-
102
- int rett = generatedValue.compare(referenceValue);
103
- printf("%d\n", rett);
104
- return (rett == 0);
105
- #endif
106
81
}
107
82
108
83
template <typename T>
0 commit comments