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 <string.h> 17#include "test.h" 18 19char one[50]; 20char two[50]; 21 22/** 23 * @tc.name : memmove_0100 24 * @tc.desc : The source address and the destination address are equal, and no copying is performed. 25 * @tc.level : Level 1 26 */ 27void memmove_0100(void) 28{ 29 memset(one, 0, sizeof(one)); 30 31 strcpy(one, "abcdefgh"); 32 memmove(one, one, 9); 33 if (strcmp(one, "abcdefgh")) { 34 t_error("%s memmove failed\n", __func__); 35 } 36} 37 38/** 39 * @tc.name : memmove_0200 40 * @tc.desc : The source address and the destination address do not overlap, copy it. 41 * @tc.level : Level 0 42 */ 43void memmove_0200(void) 44{ 45 memset(one, 0, sizeof(one)); 46 memset(two, 0, sizeof(two)); 47 48 strcpy(one, "helloWorld"); 49 strcpy(two, "foo"); 50 memmove(two, one, 11); 51 if (strcmp(one, "helloWorld")) { 52 t_error("%s memmove failed\n", __func__); 53 } 54 if (strcmp(two, "helloWorld")) { 55 t_error("%s memmove failed\n", __func__); 56 } 57} 58 59/** 60 * @tc.name : memmove_0300 61 * @tc.desc : The first address of dest is less than the first address of src, and forward copy is performed. 62 * @tc.level : Level 1 63 */ 64void memmove_0300(void) 65{ 66 memset(one, 0, sizeof(one)); 67 68 strcpy(one, "abcdefgh"); 69 memmove(one + 1, one + 2, 7); 70 if (strcmp(one, "acdefgh")) { 71 t_error("%s memmove failed\n", __func__); 72 } 73} 74 75/** 76 * @tc.name : memmove_0400 77 * @tc.desc : The first address of dest is greater than the first address of src, and reverse copy is performed. 78 * @tc.level : Level 1 79 */ 80void memmove_0400(void) 81{ 82 memset(one, 0, sizeof(one)); 83 84 strcpy(one, "abcdefgh"); 85 memmove(one + 1, one, 9); 86 if (strcmp(one, "aabcdefgh")) { 87 t_error("%s memmove failed\n", __func__); 88 } 89} 90 91int main(int argc, char *argv[]) 92{ 93 memmove_0100(); 94 memmove_0200(); 95 memmove_0300(); 96 memmove_0400(); 97 98 return t_status; 99}