0

I am trying to convert my JSON object to a string in test case 1 and 4. When test case 4 is removed, the code works properly, like the output shows up. But when I include test case 4, the code won't run. VS Code says segmentation error. I tried doing j.get<decltype(s)>()for both and the code would compile, but the output won't show up. Any solutions?

    #include "records_manager_test.hpp"
    #include "records_manager.hpp"

    #include "nlohmann/json.hpp"

    using json = nlohmann::json;

    bool RecordsManagerTest::test1(){ //To test JSON
    json j = {
                {"1", {
                {"CategoryID",67},
                {"PatientID",90},
                {"Name","Foo"},
                {"Address","Bar"},
                {"DOB","100980"}
            }},
            {"2",{
                {"CategoryID", 6},
                {"PatientID", 9},
                {"Name", "Ryan"},
                {"Address", "161 University Ave"},
                {"DOB", "180998"}
            }}
        };
string s = j.dump(4);  //Stringfying JSON
RecordsManager test(s);
if(test.insertRecord(89,89,"Eric","161 University Avenue","010195"));
{
    test.printAsJSON();
    return true;
}
}

bool RecordsManagerTest::test2(){  // To test insert of record
RecordsManager test;
if(test.insertRecord(88,89,"Eric","161 University Avenue","040485")){
    if(test.insertRecord(88,90,"Ryan","161 University Avenue","160695")){
        return true;
    }
}
return false;
}

bool RecordsManagerTest::test3(){   //To test removal of record
RecordsManager test;
test.insertRecord(88,89,"Eric","dfdf","46465");
test.insertRecord(88,90,"Eric","dfdf","46465");
if(test.removeRecord(89,89))
    {
        test.printAsJSON();
        return true;
    }
return false;
 }

bool RecordsManagerTest::test4(){ //To test JSON
json j = {
            {"1", {
                {"CategoryID",67},
                {"PatientID",90},
                {"Name","Foo"},
                {"Address","Bar"},
                {"DOB","100980"}
            }},
            {"2",{
                {"CategoryID", 6},
                {"PatientID", 9},
                {"Name", "Ryan"},
                {"Address", "161 University Ave"},
                {"DOB", "180998"}
            }}
        };
//Stringfying JSON
string s1 = j.dump(4);
RecordsManager test(s1);
if(test.insertRecord(89,89,"Eric","161 University Avenue","010195"));
{
    test.printAsJSON();
    return true;
}
}
RSA
  • 1
  • *VS Code says segmentation error.* -- Which means your program has one or more bugs. What happens if you just have test case 4 by itself? Also, which line brings up the segmentation error? – PaulMcKenzie May 28 '18 at 03:07
  • The segmentation error comes up in my class file. When I have just test case 4, the code would run and populate the list and print it. I have checked the code multiple times and there were no errors. This error only arises when I have both test case 1 and test case 4 – RSA May 29 '18 at 00:54
  • You still haven't mentioned which line causes the issue. Are you using your debugger? – PaulMcKenzie May 29 '18 at 01:32
  • Yes, the error comes in another file where I have defined the class. The weird thing is that sometimes this error comes up and other times it would compile but the output window won't show up. Yeah, I am using a debugger. – RSA May 29 '18 at 22:54

0 Answers0