diff --git a/test/src/fuzzer-parse_stl.cpp b/test/src/fuzzer-parse_stl.cpp index 50f9236b7..19082e06d 100644 --- a/test/src/fuzzer-parse_stl.cpp +++ b/test/src/fuzzer-parse_stl.cpp @@ -61,13 +61,47 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) assert(j_vector == j_list); assert(j_vector == j_flist); + // iterating json array and testing get() method + for(json::iterator it = j_vector.begin(); it != j_vector.end(); ++it) + { + try + { + int temp = (*it).get(); + } + catch(const json::type_error) + { + // input might not be convertible to integer + } + } + + for(auto& element : j_vector) + { + // range-based iteration + } + + json j_vector2; + json j_vector3; + + for(int i = 0; i < (int)j_vector.size(); ++i) + { + auto temp = j_vector.at(i); + // testing at() method + j_vector2.push_back(temp); + j_vector3.emplace_back(temp); + // testing push_back and emplace back methods + } + + // these jsons must be the same + assert(j_vector == j_vector2); + assert(j_vector == j_vector3); + std::map mp; std::unordered_map ump; std::multimap mmp; std::unordered_multimap ummp; // converting each consecutive entry in the vector into a key-value pair - for(int i=1; i insert_data = std::make_pair(vec[i-1], vec[i]); mp.insert(insert_data); @@ -81,6 +115,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) json j_multimap(mmp); json j_umultimap(ummp); + // iterating json map + for(json::iterator it = j_map.begin(); it != j_map.end(); ++it) + { + auto temp1 = it.key(); + auto temp2 = it.value(); + } + try { // parse input directly @@ -102,42 +143,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { // out of range errors may happen if provided sizes are excessive } - // try - // { - // // step 1: parse input - // json j1 = json::parse(data, data + size); - - // try - // { - // // step 2: round trip - - // // first serialization - // std::string s1 = j1.dump(); - - // // parse serialization - // json j2 = json::parse(s1); - - // // second serialization - // std::string s2 = j2.dump(); - - // // serializations must match - // assert(s1 == s2); - // } - // catch (const json::parse_error&) - // { - // // parsing a JSON serialization must not fail - // assert(false); - // } - // } - // catch (const json::parse_error&) - // { - // // parse errors are ok, because input may be random bytes - // } - // catch (const json::out_of_range&) - // { - // // out of range errors may happen if provided sizes are excessive - // } - - // return 0 - non-zero return values are reserved for future use return 0; }