• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2024 SwanLink (Jiangsu) Technology Development 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 #include "napi_error_test.h"
16 //CreateDate
17 //return not ok
TestCreateDateTest1(JSVM_Env env,JSVM_CallbackInfo info)18 [[maybe_unused]] JSVM_Value TestCreateDateTest1(JSVM_Env env, JSVM_CallbackInfo info)
19 {
20     size_t argc = 1;
21     JSVM_Value argv[1] = {nullptr};
22     OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr);
23     //create date
24     double dateValue = 0;
25     JSVM_Value rstDate = nullptr;
26     JSVM_Status status = OH_JSVM_CreateDate(env, dateValue, &rstDate);
27     if (status != JSVM_OK) {
28         OH_JSVM_ThrowError(env, nullptr, "TestCreateDateTest1: OH_JSVM_CreateDate Failed");
29         return nullptr;
30     }
31 
32     bool result = true;
33     JSVM_Value value = nullptr;
34     OH_JSVM_GetBoolean(env, result, &value);
35     return value;
36 }
37 //OK
TestGetDateValueTest1(JSVM_Env env,JSVM_CallbackInfo info)38 [[maybe_unused]] JSVM_Value TestGetDateValueTest1(JSVM_Env env, JSVM_CallbackInfo info)
39 {
40     size_t argc = 1;
41     JSVM_Value argv[1] = {nullptr};
42     OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr);
43     //create date
44     double dateValue = 1501924876711;
45     JSVM_Value rstDate;
46     JSVM_Status status = OH_JSVM_CreateDate(env, dateValue, &rstDate);
47     if (status != JSVM_OK) {
48         OH_JSVM_ThrowError(env, nullptr, "TestGetDateValueTest1: OH_JSVM_CreateDate Failed");
49         return nullptr;
50     }
51     double  getDateValue = 0;
52     status = OH_JSVM_GetDateValue(env, rstDate, &getDateValue);
53     if (status != JSVM_OK) {
54         OH_JSVM_ThrowError(env, nullptr, "TestGetDateValueTest1: OH_JSVM_GetDateValue Failed");
55         return nullptr;
56     }
57     if (dateValue != getDateValue) {
58         OH_JSVM_ThrowError(env, nullptr, "TestGetDateValueTest1: OH_JSVM_GetDateValue dateValue!=getDateValue Failed");
59         return nullptr;
60     }
61 
62     bool result = true;
63     JSVM_Value value = nullptr;
64     OH_JSVM_GetBoolean(env, result, &value);
65     return value;
66 }
67 //value is null , return n-OK
TestIsDateTest1(JSVM_Env env,JSVM_CallbackInfo info)68 [[maybe_unused]] JSVM_Value TestIsDateTest1(JSVM_Env env, JSVM_CallbackInfo info)
69 {
70     size_t argc = 1;
71     JSVM_Value argv[1] = {nullptr};
72     OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr);
73 
74     JSVM_Value rstDate = nullptr;
75     bool bDateType = false;
76     JSVM_Status status = OH_JSVM_IsDate(env, rstDate, &bDateType);
77     if (status == JSVM_OK) {
78         OH_JSVM_ThrowError(env, nullptr, "TestIsDateTest1: OH_JSVM_IsDate Failed");
79         return nullptr;
80     }
81 
82     bool result = true;
83     JSVM_Value value = nullptr;
84     OH_JSVM_GetBoolean(env, result, &value);
85     return value;
86 }
87 // create -- is -- get
TestDateCombinationTest1(JSVM_Env env,JSVM_CallbackInfo info)88 [[maybe_unused]] JSVM_Value TestDateCombinationTest1(JSVM_Env env, JSVM_CallbackInfo info)
89 {
90     size_t argc = 1;
91     JSVM_Value argv[1] = {nullptr};
92     OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr);
93 
94     //create date
95     double dateValue = 1501924876711;
96     JSVM_Value rstDate;
97     JSVM_Status status = OH_JSVM_CreateDate(env, dateValue, &rstDate);
98     if (status != JSVM_OK) {
99         OH_JSVM_ThrowError(env, nullptr, "TestGetDateValueTest1: OH_JSVM_CreateDate Failed");
100         return nullptr;
101     }
102     // is date
103     bool bDateType = false;
104     status = OH_JSVM_IsDate(env, rstDate, &bDateType);
105     if (status != JSVM_OK) {
106         OH_JSVM_ThrowError(env, nullptr, "TestDateCombinationTest1: OH_JSVM_IsDate Failed");
107         return nullptr;
108     }
109     if (!bDateType) {
110         OH_JSVM_ThrowError(env, nullptr, "TestIsDateTest1: OH_JSVM_IsDate bDateType is false");
111         return nullptr;
112     }
113     double  getDateValue = 0;
114     status = OH_JSVM_GetDateValue(env, rstDate, &getDateValue);
115     if (status != JSVM_OK) {
116         OH_JSVM_ThrowError(env, nullptr, "TestGetDateValueTest1: OH_JSVM_GetDateValue Failed");
117         return nullptr;
118     }
119     if (dateValue != getDateValue) {
120         OH_JSVM_ThrowError(env, nullptr, "TestGetDateValueTest1: OH_JSVM_GetDateValue dateValue!=getDateValue Failed");
121         return nullptr;
122     }
123 
124     bool result = true;
125     JSVM_Value value = nullptr;
126     OH_JSVM_GetBoolean(env, result, &value);
127     return value;
128 }