1 /*
2  * Copyright (c) 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 <fstream>
17 #include <gtest/gtest.h>
18 
19 #include "drawing_font_collection.h"
20 #include "drawing_register_font.h"
21 #include "drawing_text_declaration.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 static const char* g_fontFamily = "Roboto-Black";
28 static const char* g_fontPath = "/data/Roboto-Black.ttf";
29 
30 class NativeDrawingRegisterFontTest : public testing::Test {
31 };
32 
33 /*
34  * @tc.name: NativeDrawingRegisterFontTest001
35  * @tc.desc: test for register font
36  * @tc.type: FUNC
37  */
HWTEST_F(NativeDrawingRegisterFontTest, NativeDrawingRegisterFontTest001, TestSize.Level1)38 HWTEST_F(NativeDrawingRegisterFontTest, NativeDrawingRegisterFontTest001, TestSize.Level1)
39 {
40     OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection();
41     uint32_t errorCode = OH_Drawing_RegisterFont(fontCollection, g_fontFamily, g_fontPath);
42     std::ifstream fileStream(g_fontPath);
43     if (fileStream.is_open()) {
44         EXPECT_EQ(errorCode, 0);
45         fileStream.close();
46     } else {
47         EXPECT_EQ(errorCode, 1);
48     }
49     OH_Drawing_DestroyFontCollection(fontCollection);
50 }
51 
52 /*
53  * @tc.name: NativeDrawingRegisterFontTest002
54  * @tc.desc: test for register font
55  * @tc.type: FUNC
56  */
HWTEST_F(NativeDrawingRegisterFontTest, NativeDrawingRegisterFontTest002, TestSize.Level1)57 HWTEST_F(NativeDrawingRegisterFontTest, NativeDrawingRegisterFontTest002, TestSize.Level1)
58 {
59     OH_Drawing_FontCollection* fontCollection = OH_Drawing_CreateFontCollection();
60     uint32_t errorCode = OH_Drawing_RegisterFontBuffer(fontCollection, g_fontFamily, nullptr, 128);
61     std::ifstream fileStream(g_fontPath);
62     if (fileStream.is_open()) {
63         EXPECT_EQ(errorCode, 0);
64         fileStream.close();
65     } else {
66         EXPECT_EQ(errorCode, 6);
67     }
68     OH_Drawing_DestroyFontCollection(fontCollection);
69 }
70 }