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 <stdlib.h> 17#include <time.h> 18#include "difftime_data.h" 19#include "functionalext.h" 20 21extern double __difftime64 (time_t, time_t); 22 23/** 24 * @tc.name : difftime_0100 25 * @tc.desc : according to different time zones, calculate the time difference between two moments 26 * @tc.level : Level 0 27 */ 28void difftime_0100(void) 29{ 30 time_t timeStart = 20000; 31 time_t timeEnd = 20010; 32 for (int32_t i = 0; i < (int32_t)(sizeof(test_difftime_data) / sizeof(test_difftime_data[0])); i++) { 33 const char *handlerChar = test_handle_path(test_difftime_data[i].tz); 34 if (!handlerChar) { 35 t_error("difftime_0100 failed: handlerChar is NULL\n"); 36 continue; 37 } 38 39 setenv("TZ", handlerChar, 1); 40 tzset(); 41 double returnVal; 42 returnVal = difftime(timeEnd, timeStart); 43 EXPECT_TRUE("difftime_0100", 44 abs(test_difftime_data[i].result - returnVal) >= 0 && abs(test_difftime_data[i].result - returnVal) < 1); 45 } 46} 47 48 49/** 50 * @tc.name : difftime64_0100 51 * @tc.desc : according to different time zones, calculate the time difference between two moments 52 * @tc.level : Level 0 53 */ 54void difftime64_0100(void) 55{ 56 time_t timeStart = 20000; 57 time_t timeEnd = 20010; 58 for (int32_t i = 0; i < (int32_t)(sizeof(test_difftime_data) / sizeof(test_difftime_data[0])); i++) { 59 const char *handlerChar = test_handle_path(test_difftime_data[i].tz); 60 if (!handlerChar) { 61 t_error("difftime_0100 failed: handlerChar is NULL\n"); 62 continue; 63 } 64 65 setenv("TZ", handlerChar, 1); 66 tzset(); 67 double returnVal; 68 returnVal = __difftime64(timeEnd, timeStart); 69 EXPECT_TRUE("difftime64_0100", 70 abs(test_difftime_data[i].result - returnVal) >= 0 && abs(test_difftime_data[i].result - returnVal) < 1); 71 } 72} 73 74int main(void) 75{ 76 difftime_0100(); 77 difftime64_0100(); 78 return t_status; 79}