~aleteoryx/muditaos

ref: e07f2db550f1b881a92a25a420289b1a704256c6 muditaos/module-services/service-db/test/test-service-db-api.cpp -rw-r--r-- 2.7 KiB
e07f2db5 — rrandomsky [MOS-864] Fix for country code in new contact based on deleted one 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <catch2/catch.hpp> // for AssertionHandler, operator""_catch_sr, SourceLineInfo, StringRef, REQUIRE, Section, SECTION, SectionInfo, TEST_CASE
#include <module-db/Interface/ContactRecord.hpp> // for ContactRecord
#include <service-db/DBServiceAPI.hpp> // for DBServiceAPI, DBServiceAPI::noError, DBServiceAPI::ContactVerificationError, DBServiceAPI::emptyContactError
#include <memory> // for allocator

TEST_CASE("DB_API")
{
    SECTION("DBServiceAPI::verifyContact emptyContactError")
    {
        ContactRecord testRecord;

        DBServiceAPI::ContactVerificationResult err = DBServiceAPI::verifyContact(nullptr, testRecord);
        REQUIRE(err == DBServiceAPI::ContactVerificationResult::emptyContact);

        testRecord.primaryName = "testName";
        err                    = DBServiceAPI::verifyContact(nullptr, testRecord);
        testRecord.primaryName.clear();
        REQUIRE(err == DBServiceAPI::ContactVerificationResult::success);

        testRecord.alternativeName = "testName";
        err                        = DBServiceAPI::verifyContact(nullptr, testRecord);
        testRecord.alternativeName.clear();
        REQUIRE(err == DBServiceAPI::ContactVerificationResult::success);

        // Here should be tested contact with single number, but it would require involving sys::bus.

        testRecord.mail = "test@mail.com";
        err             = DBServiceAPI::verifyContact(nullptr, testRecord);
        testRecord.mail.clear();
        REQUIRE(err == DBServiceAPI::ContactVerificationResult::success);

        testRecord.mail = "test@mail.com";
        err             = DBServiceAPI::verifyContact(nullptr, testRecord);
        testRecord.mail.clear();
        REQUIRE(err == DBServiceAPI::ContactVerificationResult::success);

        testRecord.speeddial = "1";
        err                  = DBServiceAPI::verifyContact(nullptr, testRecord);
        testRecord.speeddial.clear();
        REQUIRE(err == DBServiceAPI::ContactVerificationResult::emptyContact);

        testRecord.address = "test address";
        err                = DBServiceAPI::verifyContact(nullptr, testRecord);
        testRecord.address.clear();
        REQUIRE(err == DBServiceAPI::ContactVerificationResult::success);

        testRecord.note = "test note";
        err             = DBServiceAPI::verifyContact(nullptr, testRecord);
        testRecord.note.clear();
        REQUIRE(err == DBServiceAPI::ContactVerificationResult::success);

        err = DBServiceAPI::verifyContact(nullptr, testRecord);
        REQUIRE(err == DBServiceAPI::ContactVerificationResult::emptyContact);
    }
}