1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 18 #include "error_multimodal.h" 19 #include "util.h" 20 21 22 namespace OHOS { 23 namespace MMI { 24 namespace { 25 using namespace testing::ext; 26 } // namespace 27 28 class UtilTest : public testing::Test { 29 public: SetUpTestCase(void)30 static void SetUpTestCase(void) {} TearDownTestCase(void)31 static void TearDownTestCase(void) {} 32 }; 33 34 /** 35 * @tc.name:getEnumString_001 36 * @tc.desc:Verify get enum string 37 * @tc.type: FUNC 38 * @tc.require: 39 */ 40 HWTEST_F(UtilTest, getEnumString_001, TestSize.Level1) 41 { 42 const int32_t errorCodeEnum = MSG_SEND_FAIL; 43 const char *retResult = GetMmiErrorTypeDesc(errorCodeEnum); 44 EXPECT_STREQ(retResult, "Send Message Failed"); 45 } 46 47 /** 48 * @tc.name:getEnumString_002 49 * @tc.desc:Verify get enum string 50 * @tc.type: FUNC 51 * @tc.require: 52 */ 53 HWTEST_F(UtilTest, getEnumString_002, TestSize.Level1) 54 { 55 const int32_t errorCodeEnum = NON_STD_EVENT; 56 const char *retResult = GetMmiErrorTypeDesc(errorCodeEnum); 57 EXPECT_STREQ(retResult, "Non-Standardized Event"); 58 } 59 60 /** 61 * @tc.name:getEnumString_003 62 * @tc.desc:Verify get enum string 63 * @tc.type: FUNC 64 * @tc.require: 65 */ 66 HWTEST_F(UtilTest, getEnumString_003, TestSize.Level1) 67 { 68 const int32_t errorCodeEnum = UNKNOWN_EVENT; 69 const char *retResult = GetMmiErrorTypeDesc(errorCodeEnum); 70 EXPECT_STREQ(retResult, "Unknown Event"); 71 } 72 73 /** 74 * @tc.name:getEnumString_004 75 * @tc.desc:Verify get enum string 76 * @tc.type: FUNC 77 * @tc.require: 78 */ 79 HWTEST_F(UtilTest, getEnumString_004, TestSize.Level1) 80 { 81 const int32_t errorCodeEnum = UNPROC_MSG; 82 const char *retResult = GetMmiErrorTypeDesc(errorCodeEnum); 83 EXPECT_STREQ(retResult, "Unprocessed Message"); 84 } 85 86 /** 87 * @tc.name:getEnumString_005 88 * @tc.desc:Verify get enum string 89 * @tc.type: FUNC 90 * @tc.require: 91 */ 92 HWTEST_F(UtilTest, getEnumString_005, TestSize.Level1) 93 { 94 const int32_t errorCodeEnum = UNKNOWN_MSG_ID; 95 const char *retResult = GetMmiErrorTypeDesc(errorCodeEnum); 96 EXPECT_STREQ(retResult, "Unknown Message Id"); 97 } 98 99 /** 100 * @tc.name:GetMicrotime 101 * @tc.desc:Verify get micro time 102 * @tc.type: FUNC 103 * @tc.require: 104 */ 105 HWTEST_F(UtilTest, GetMicrotime, TestSize.Level1) 106 { 107 int64_t retResult = GetMicrotime(); 108 EXPECT_TRUE(retResult > 0); 109 } 110 111 /** 112 * @tc.name:GetMillisTime 113 * @tc.desc:Verify get millis time 114 * @tc.type: FUNC 115 * @tc.require: 116 */ 117 HWTEST_F(UtilTest, GetMillisTime, TestSize.Level1) 118 { 119 int64_t retResult = GetMillisTime(); 120 EXPECT_TRUE(retResult > 0); 121 } 122 123 /** 124 * @tc.name:UuIdGenerate 125 * @tc.desc:Verify generate uuid 126 * @tc.type: FUNC 127 * @tc.require: 128 */ 129 HWTEST_F(UtilTest, UuIdGenerate, TestSize.Level1) 130 { 131 std::string retResult = UuIdGenerate(); 132 EXPECT_TRUE(retResult.length() == 0); 133 } 134 135 /** 136 * @tc.name:GetUUid 137 * @tc.desc:Verify get uuid 138 * @tc.type: FUNC 139 * @tc.require: 140 */ 141 HWTEST_F(UtilTest, GetUUid, TestSize.Level1) 142 { 143 std::string retResult = GetUUid(); 144 EXPECT_TRUE(retResult.length() >= 0); 145 } 146 147 /** 148 * @tc.name:GetThisThreadIdOfString 149 * @tc.desc:Verify get thread id 150 * @tc.type: FUNC 151 * @tc.require: 152 */ 153 HWTEST_F(UtilTest, GetThisThreadIdOfString, TestSize.Level1) 154 { 155 std::string retResult = GetThisThreadIdOfString(); 156 EXPECT_TRUE(retResult.length() >= 0); 157 } 158 159 HWTEST_F(UtilTest, GetThisThreadId, TestSize.Level1) 160 { 161 uint64_t retResult = GetThisThreadId(); 162 EXPECT_TRUE(retResult >= 0); 163 } 164 165 /** 166 * @tc.name:StringToken_001 167 * @tc.desc:Verify string token 168 * @tc.type: FUNC 169 * @tc.require: 170 */ 171 HWTEST_F(UtilTest, StringToken_001, TestSize.Level1) 172 { 173 std::string str = "sdf_wef_1"; 174 const std::string sep = "sdf_wef_1.sss"; 175 std::string token = "_"; 176 StringToken(str, sep, token); 177 } 178 179 /** 180 * @tc.name:StringToken_002 181 * @tc.desc:Verify string token 182 * @tc.type: FUNC 183 * @tc.require: 184 */ 185 HWTEST_F(UtilTest, StringToken_002, TestSize.Level1) 186 { 187 std::string str = { 0 }; 188 const std::string sep; 189 std::string token; 190 StringToken(str, sep, token); 191 } 192 193 /** 194 * @tc.name:StringToken_003 195 * @tc.desc:Verify string token 196 * @tc.type: FUNC 197 * @tc.require: 198 */ 199 HWTEST_F(UtilTest, StringToken_003, TestSize.Level1) 200 { 201 std::string str = { 0, 1, 2, 3 }; 202 const std::string sep = { 2 }; 203 std::string token; 204 StringToken(str, sep, token); 205 } 206 207 /** 208 * @tc.name:StringSplit 209 * @tc.desc:Verify string token 210 * @tc.type: FUNC 211 * @tc.require: 212 */ 213 HWTEST_F(UtilTest, StringSplit, TestSize.Level1) 214 { 215 const std::string str; 216 const std::string sep; 217 std::vector<std::string> vecList; 218 StringSplit(str, sep, vecList); 219 } 220 } // namespace MMI 221 } // namespace OHOS 222