Flutter Engine
ICUTestBase.h
Go to the documentation of this file.
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/mman.h>
27 #include <sys/stat.h>
28 
29 namespace minikin {
30 
31 class ICUTestBase : public testing::Test {
32  protected:
33  virtual void SetUp() override {
34  const char* fn = "/system/usr/icu/" U_ICUDATA_NAME ".dat";
35  int fd = open(fn, O_RDONLY);
36  ASSERT_NE(-1, fd);
37  struct stat sb;
38  ASSERT_EQ(0, fstat(fd, &sb));
39  void* data = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
40 
41  UErrorCode errorCode = U_ZERO_ERROR;
42  udata_setCommonData(data, &errorCode);
43  ASSERT_TRUE(U_SUCCESS(errorCode));
44  u_init(&errorCode);
45  ASSERT_TRUE(U_SUCCESS(errorCode));
46  }
47 
48  virtual void TearDown() override { u_cleanup(); }
49 };
50 
51 } // namespace minikin
52 #endif // MINIKIN_TEST_ICU_TEST_BASE_H
virtual void SetUp() override
Definition: ICUTestBase.h:33
virtual void TearDown() override
Definition: ICUTestBase.h:48