• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "widget_image.h"
18 #include "ui_model.h"
19 
20 using namespace OHOS::uitest;
21 using namespace std;
22 
23 static constexpr auto ATTR_TEXT = "text";
24 
TEST(WidgetImageTest,compareEquals)25 TEST(WidgetImageTest, compareEquals)
26 {
27     map<string, string> attributes;
28     attributes[ATTR_HASHCODE] = "123";
29     attributes[ATTR_TEXT] = "wyz";
30     attributes["id"] = "888";
31     WidgetImage image0;
32     image0.SetAttributes(attributes);
33 
34     WidgetImage image1;
35     image1.SetAttributes(attributes);
36     // all attributes are same, should be equal
37     ASSERT_TRUE(image0.Compare(image1));
38 
39     attributes[ATTR_TEXT] = "wlj";
40     image1.SetAttributes(attributes);
41     // the hashcode are equal, difference of other attributes should be ignored
42     ASSERT_TRUE(image0.Compare(image1));
43 
44     attributes[ATTR_HASHCODE] = "321";
45     attributes[ATTR_TEXT] = "wyz";
46     image1.SetAttributes(attributes);
47     // the hashcode are not equal, all the other attributes must be same to make equal
48     ASSERT_TRUE(image0.Compare(image1));
49     attributes[ATTR_HASHCODE] = "321";
50     attributes[ATTR_TEXT] = "zl";
51     image1.SetAttributes(attributes);
52     ASSERT_FALSE(image0.Compare(image1));
53 }
54 
TEST(WidgetImageTest,setGetAttributes)55 TEST(WidgetImageTest, setGetAttributes)
56 {
57     map<string, string> attributes;
58     attributes[ATTR_HASHCODE] = "123";
59     attributes[ATTR_TEXT] = "wyz";
60     attributes["id"] = "888";
61     WidgetImage image0;
62     image0.SetAttributes(attributes);
63 
64     // should retrieve correct and full attributes
65     for (auto&[key, val]:attributes) {
66         ASSERT_EQ(val, image0.GetAttribute(key, ""));
67     }
68 }