1 /*
2  * Copyright (C) 2015 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 #ifndef MINIKIN_TEST_ICU_TEST_BASE_H
18 #define MINIKIN_TEST_ICU_TEST_BASE_H
19 
20 #include <gtest/gtest.h>
21 #include <unicode/uclean.h>
22 #include <unicode/udata.h>
23 
24 // low level file access for mapping ICU data
25 #include <fcntl.h>
26 #include <sys/stat.h>
27 #include <sys/mman.h>
28 
29 class ICUTestBase : public testing::Test {
30 protected:
SetUp()31     virtual void SetUp() override {
32         const char* fn = "/system/usr/icu/" U_ICUDATA_NAME ".dat";
33         int fd = open(fn, O_RDONLY);
34         ASSERT_NE(-1, fd);
35         struct stat sb;
36         ASSERT_EQ(0, fstat(fd, &sb));
37         void* data = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
38 
39         UErrorCode errorCode = U_ZERO_ERROR;
40         udata_setCommonData(data, &errorCode);
41         ASSERT_TRUE(U_SUCCESS(errorCode));
42         u_init(&errorCode);
43         ASSERT_TRUE(U_SUCCESS(errorCode));
44     }
45 
TearDown()46     virtual void TearDown() override {
47         u_cleanup();
48     }
49 };
50 
51 
52 #endif  //  MINIKIN_TEST_ICU_TEST_BASE_H
53