deviceauth_standard_test.cpp 2.5 KB
Newer Older
L
li-zipei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <ctime>
#include <gtest/gtest.h>
L
li-zipei 已提交
18 19 20
#include "deviceauth_test_mock.h"
#include "deviceauth_standard_test.h"
extern "C" {
L
li-zipei 已提交
21 22
#include "common_defs.h"
#include "json_utils.h"
L
li-zipei 已提交
23 24 25
#include "device_auth.h"
#include "device_auth_defines.h"
#include "database_manager.h"
L
li-zipei 已提交
26 27 28
#include "hc_condition.h"
#include "hc_mutex.h"
#include "hc_types.h"
L
li-zipei 已提交
29
}
L
li-zipei 已提交
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

using namespace std;
using namespace testing::ext;

namespace
{
    static bool g_isNeedContinue = false;
    static int64_t g_requestId = 0L;
    static int g_operationCode = -1;
    static int g_errorCode = 1;
    static char *g_tempStr = nullptr;
    static int g_messageCode = -1;

void ClearTempValue()
{
    g_isNeedContinue = false;
    g_requestId = 0L;
    g_operationCode = -1;
    g_errorCode = 1;
    g_tempStr = nullptr;
    g_messageCode = -1;
}

enum {
    GROUP_CREATED = 0,
    GROUP_DELETED,
    DEVICE_BOUND,
    DEVICE_UNBOUND,
    DEVICE_NOT_TRUSTED,
    LAST_GROUP_DELETED,
    TRUSTED_DEVICE_NUM_CHANGED
};

/* test suit - GET_INSTANCE */
class GET_INSTANCE : public testing::Test {
public:
    static void SetUpTestCase(void);

    static void TearDownTestCase(void);

    void SetUp();

    void TearDown();
};

void GET_INSTANCE::SetUpTestCase()
{
    int32_t ret = InitDeviceAuthService();
    ASSERT_EQ(ret == HC_SUCCESS, true);
}

void GET_INSTANCE::TearDownTestCase()
{
    DestroyDeviceAuthService();
    ClearTempValue();
}

void GET_INSTANCE::SetUp()
{
}

void GET_INSTANCE::TearDown()
{
}



L
li-zipei 已提交
97
class REGISTER_CALLBACK : public testing::Test {
L
li-zipei 已提交
98
public:
L
li-zipei 已提交
99
    const DeviceGroupManager *gm = GetGmInstance();
L
li-zipei 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    static void SetUpTestCase(void);

    static void TearDownTestCase(void);

    void SetUp();

    void TearDown();
};


/* start cases */
/**
 * @tc.name: GET_INSTANCE.TC_GET_GM_INSTANCE
 * @tc.desc: Test GetGmInstance interface function;
 * @tc.type: FUNC
 */
HWTEST_F(GET_INSTANCE, TC_GET_GM_INSTANCE, TestSize.Level1)
{
    const DeviceGroupManager *gm = GetGmInstance();
    ASSERT_NE(gm, nullptr);
}
}