FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_CopyFile.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2010-2011 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
10 #include "run_tests.h"
11 
12 /* local variables */
13 static char *Src = "";
14 static char *Dst = NULL;
15 static struct stat statSrc;
16 static struct stat statDst;
17 static int Result = 0;
18 
19 
24 {
25  Dst = (char *)malloc(100);
26  return 0;
27 }
28 
33 {
34  free(Dst);
35  return 0;
36 }
37 
38 
39 /* test functions */
40 
49 {
50  Src = "../testdata/test.iso";
51  deleteTmpFiles("./test-result/");
52  strcpy(Dst, "./test-result/hello");
53  stat(Src, &statSrc);
54  Result = CopyFile(Src, Dst);
55  stat(Dst, &statDst);
56  FO_ASSERT_EQUAL((int)statSrc.st_size, (int)statDst.st_size);
57  FO_ASSERT_EQUAL(Result, 0);
58 }
59 
68 {
69  Src = "../testdata";
70  strcpy(Dst, "./test-result/hello");
71  deleteTmpFiles("./test-result/");
72  Result = CopyFile(Src, Dst);
73  exists = file_dir_exists("./test-result/hello/test.tar");
74  FO_ASSERT_EQUAL(exists, 0); // no existing
75  FO_ASSERT_EQUAL(Result, 1); // is directory
76 }
77 
86 {
87  Src = "";
88  strcpy(Dst, "./test-result/hello");
89  deleteTmpFiles("./test-result/");
90  Result = CopyFile(Src, Dst);
91  exists = file_dir_exists("./test-result");
92  FO_ASSERT_EQUAL(exists, 0); // no existing
93  FO_ASSERT_EQUAL(Result, 1); // failed
94 }
95 
96 
97 /* ************************************************************************** */
98 /* **** cunit test cases **************************************************** */
99 /* ************************************************************************** */
100 
101 CU_TestInfo CopyFile_testcases[] =
102 {
103  {"CopyFile: file name", testCopyFileNormalFile},
104  {"CopyFile: dir name", testCopyFileNormalDir},
105  {"CopyFile: file name is empty", testCopyFileAbnormal},
106  CU_TEST_INFO_NULL
107 };
void CopyFile(char *Source, char *Type, char *Name)
Definition: repcopyin.c:39
void testCopyFileNormalFile()
copy directory
Definition: test_CopyFile.c:48
int CopyFileClean()
clean env and others
Definition: test_CopyFile.c:32
int CopyFileInit()
initialize
Definition: test_CopyFile.c:23
static struct stat statSrc
Stat of source.
Definition: test_CopyFile.c:15
static int Result
Result of calls.
Definition: test_CopyFile.c:17
CU_TestInfo CopyFile_testcases[]
Copy test cases.
static struct stat statDst
Stat of destination.
Definition: test_CopyFile.c:16
void testCopyFileNormalDir()
copy directory
Definition: test_CopyFile.c:67
void testCopyFileAbnormal()
parameters are null
Definition: test_CopyFile.c:85
static char * Dst
Destination location.
Definition: test_CopyFile.c:14
static char * Src
Souce location.
Definition: test_CopyFile.c:13
int file_dir_exists(char *path_name)
test if a file or directory exists
Definition: run_tests.c:90
int exists
Default not exists.
Definition: run_tests.c:20