"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/unittest/jsoncheckertest.cpp" between
rapidjson-1.0.2.tar.gz and rapidjson-1.1.0.tar.gz

About: RapidJSON is a fast JSON parser/generator for C++ with both SAX/DOM style API.

jsoncheckertest.cpp  (rapidjson-1.0.2):jsoncheckertest.cpp  (rapidjson-1.1.0)
skipping to change at line 23 skipping to change at line 23
// specific language governing permissions and limitations under the License. // specific language governing permissions and limitations under the License.
#include "unittest.h" #include "unittest.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
using namespace rapidjson; using namespace rapidjson;
static char* ReadFile(const char* filename, size_t& length) { static char* ReadFile(const char* filename, size_t& length) {
const char *paths[] = { const char *paths[] = {
"jsonchecker/%s", "jsonchecker",
"bin/jsonchecker/%s", "bin/jsonchecker",
"../bin/jsonchecker/%s", "../bin/jsonchecker",
"../../bin/jsonchecker/%s", "../../bin/jsonchecker",
"../../../bin/jsonchecker/%s" "../../../bin/jsonchecker"
}; };
char buffer[1024]; char buffer[1024];
FILE *fp = 0; FILE *fp = 0;
for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) { for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) {
sprintf(buffer, paths[i], filename); sprintf(buffer, "%s/%s", paths[i], filename);
fp = fopen(buffer, "rb"); fp = fopen(buffer, "rb");
if (fp) if (fp)
break; break;
} }
if (!fp) if (!fp)
return 0; return 0;
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
length = (size_t)ftell(fp); length = static_cast<size_t>(ftell(fp));
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
char* json = (char*)malloc(length + 1); char* json = static_cast<char*>(malloc(length + 1));
size_t readLength = fread(json, 1, length, fp); size_t readLength = fread(json, 1, length, fp);
json[readLength] = '\0'; json[readLength] = '\0';
fclose(fp); fclose(fp);
return json; return json;
} }
TEST(JsonChecker, Reader) { TEST(JsonChecker, Reader) {
char filename[256]; char filename[256];
// jsonchecker/failXX.json // jsonchecker/failXX.json
skipping to change at line 71 skipping to change at line 71
sprintf(filename, "fail%d.json", i); sprintf(filename, "fail%d.json", i);
size_t length; size_t length;
char* json = ReadFile(filename, length); char* json = ReadFile(filename, length);
if (!json) { if (!json) {
printf("jsonchecker file %s not found", filename); printf("jsonchecker file %s not found", filename);
ADD_FAILURE(); ADD_FAILURE();
continue; continue;
} }
GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak) GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak)
document.Parse((const char*)json); document.Parse(json);
EXPECT_TRUE(document.HasParseError()); EXPECT_TRUE(document.HasParseError());
document.Parse<kParseIterativeFlag>((const char*)json); document.Parse<kParseIterativeFlag>(json);
EXPECT_TRUE(document.HasParseError()); EXPECT_TRUE(document.HasParseError());
free(json); free(json);
} }
// passX.json // passX.json
for (int i = 1; i <= 3; i++) { for (int i = 1; i <= 3; i++) {
sprintf(filename, "pass%d.json", i); sprintf(filename, "pass%d.json", i);
size_t length; size_t length;
char* json = ReadFile(filename, length); char* json = ReadFile(filename, length);
if (!json) { if (!json) {
printf("jsonchecker file %s not found", filename); printf("jsonchecker file %s not found", filename);
continue; continue;
} }
GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak) GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak)
document.Parse((const char*)json); document.Parse(json);
EXPECT_FALSE(document.HasParseError()); EXPECT_FALSE(document.HasParseError());
document.Parse<kParseIterativeFlag>((const char*)json); document.Parse<kParseIterativeFlag>(json);
EXPECT_FALSE(document.HasParseError()); EXPECT_FALSE(document.HasParseError());
free(json); free(json);
} }
} }
 End of changes. 8 change blocks. 
12 lines changed or deleted 12 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)