1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <iostream>
18 #include <fstream>
19
20 #include <android-base/macros.h>
21
22 #include "simple_type.h"
23 #include "xmltest.h"
24
25 using namespace std;
26
TEST_F(XmlTest,Simpletype)27 TEST_F(XmlTest, Simpletype) {
28 using namespace simple::type;
29 for (const auto v : android::xsdc_enum_range<EnumType>()) {
30 EXPECT_NE(v, EnumType::UNKNOWN);
31 EXPECT_EQ(stringToEnumType(toString(v)), v);
32 }
33
34 string file_name = Resource("simple_type.xml");
35 SimpleTypes simple = *readSimpleTypes(file_name.c_str());
36
37 for (int i = 0; i < simple.getListInt().size(); ++i) {
38 EXPECT_EQ(simple.getListInt()[i], i + 1);
39 }
40 EXPECT_EQ(*simple.getFirstUnionTest(), "100");
41 EXPECT_EQ(simple.getYesOrNo()[0], EnumType::YES);
42 EXPECT_EQ(simple.getYesOrNo()[1], EnumType::EMPTY);
43 ofstream out("old_simple_type.xml");
44 write(out, simple);
45 SimpleTypes simple2 = *readSimpleTypes("old_simple_type.xml");
46 for (int i = 0; i < simple.getListInt().size(); ++i) {
47 EXPECT_EQ(simple.getListInt()[i], simple2.getListInt()[i]);
48 }
49 EXPECT_EQ(*simple.getFirstUnionTest(), *simple2.getFirstUnionTest());
50 EXPECT_EQ(simple.getYesOrNo()[0], simple2.getYesOrNo()[0]);
51 EXPECT_EQ(simple.getYesOrNo()[1], simple2.getYesOrNo()[1]);
52 }
53