I have 2 functions: serialise and deserialise, I want to check in the unit test whether they work correctly. But then the mistakes went up. and I don’t understand what I am saying is wrong. I need your help Test:

void UnitTests::testOne() { Task task1; task1.setQuestion("Вопрос"); task1.setAnswer("Ответ"); task1.setNumPoints(3); auto jsonObject = Archiver::serialise(&task1); Task task2 = Archiver::deserialise(&jsonObject); areEqual(task1, task2); } 

But the compiler shouts at these two lines.

  Task task2 = Archiver::deserialise(&jsonObject); areEqual(task1, task2); 

Errors

 1)error: C2664: 'std::unique_ptr<Component,std::default_delete<_Ty>> Archiver::deserialise(const QJsonObject &)': cannot convert argument 1 from 'std::unique_ptr<QJsonObject,std::default_delete<_Ty>> *' to 'const QJsonObject &' 

std :: unique_ptr Archiver :: deserialise (const QJsonObject & jsonData)

  2) error: C3861: 'areEqual': identifier not found 

but I created the function Equal in the unit test.

UPD:

  class UnitTests : public QObject { Q_OBJECT public: UnitTests(); private Q_SLOTS: void testOne(); void testSecond(); bool areEqual(const Component* comp1, const Component* comp2); }; void UnitTests::testOne() {} void UnitTests::testSecond() {} bool areEqual(const Component* comp1, const Component* comp2) {} QTEST_APPLESS_MAIN(UnitTests) #include "UnitTests.moc" 

    1 answer 1

    Your Archiver::deserialise (or is it a booster?) Function wants const QJsonObject &jsonData as const QJsonObject &jsonData , and you are trying to stick it with sdt::unique_ptr<QJsonObject> . Therefore, most likely you just need to do dereference

     Task task2 = Archiver::deserialise(*jsonObject); 

    But since I only guessed the Task type, I cannot check the solution.

    By the second error. You never said exactly where the function are Equal. And the compiler does not see it (and I also do not know where it is). But QJsonObject has an overloaded operator== , therefore, it can be compared directly. And write somewhere like that

     QVERIFY(task1 == task2); 
    • Wrote as you said 1) error error: C2440: 'initializing': cannot convert from 'std :: unique_ptr <Component, std :: default_delete <_Ty >>' to 'Task' again cannot convert - dimaAf
    • 2) I go to UnitTests like this: void UnitTests :: testOne () {} after it comes the bool areEqual function (const Component * comp1, const Component * comp2) {} and it is not clear why it cannot be seen - dimaAf
    • 1) I wrote and rolled it like this: std :: unique_ptr <Component> task2 = Archiver :: deserialise (* jsonObject); - dimaAf
    • 2) already saw the functions, but another error: error: C2664: 'bool UnitTests :: areEqual (const Component *, const Component *)': cannot convert argument 1 from 'Task' to 'const Component *' - dimaAf
    • It seems you have a problem with the types. That task, that component. Make a simple example that reproduces the problem and you can think of something. - KoVadim