FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_CopyFile.c
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright (C) 2010-2011 Hewlett-Packard Development Company, L.P.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 *********************************************************************/
21 #include "run_tests.h"
22 
23 /* local variables */
24 static char *Src = "";
25 static char *Dst = NULL;
26 static struct stat statSrc;
27 static struct stat statDst;
28 static int Result = 0;
29 
30 
35 {
36  Dst = (char *)malloc(100);
37  return 0;
38 }
39 
44 {
45  free(Dst);
46  return 0;
47 }
48 
49 
50 /* test functions */
51 
60 {
61  Src = "../testdata/test.iso";
62  deleteTmpFiles("./test-result/");
63  strcpy(Dst, "./test-result/hello");
64  stat(Src, &statSrc);
65  Result = CopyFile(Src, Dst);
66  stat(Dst, &statDst);
67  FO_ASSERT_EQUAL((int)statSrc.st_size, (int)statDst.st_size);
68  FO_ASSERT_EQUAL(Result, 0);
69 }
70 
79 {
80  Src = "../testdata";
81  strcpy(Dst, "./test-result/hello");
82  deleteTmpFiles("./test-result/");
83  Result = CopyFile(Src, Dst);
84  exists = file_dir_exists("./test-result/hello/test.tar");
85  FO_ASSERT_EQUAL(exists, 0); // no existing
86  FO_ASSERT_EQUAL(Result, 1); // is directory
87 }
88 
97 {
98  Src = "";
99  strcpy(Dst, "./test-result/hello");
100  deleteTmpFiles("./test-result/");
101  Result = CopyFile(Src, Dst);
102  exists = file_dir_exists("./test-result");
103  FO_ASSERT_EQUAL(exists, 0); // no existing
104  FO_ASSERT_EQUAL(Result, 1); // failed
105 }
106 
107 
108 /* ************************************************************************** */
109 /* **** cunit test cases **************************************************** */
110 /* ************************************************************************** */
111 
112 CU_TestInfo CopyFile_testcases[] =
113 {
114  {"CopyFile: file name", testCopyFileNormalFile},
115  {"CopyFile: dir name", testCopyFileNormalDir},
116  {"CopyFile: file name is empty", testCopyFileAbnormal},
117  CU_TEST_INFO_NULL
118 };
static struct stat statDst
Stat of destination.
Definition: test_CopyFile.c:27
static int Result
Result of calls.
Definition: test_CopyFile.c:28
void testCopyFileNormalFile()
copy directory
Definition: test_CopyFile.c:59
int file_dir_exists(char *path_name)
test if a file or directory exists
Definition: run_tests.c:136
void testCopyFileAbnormal()
parameters are null
Definition: test_CopyFile.c:96
void CopyFile(char *Source, char *Type, char *Name)
Definition: repcopyin.c:52
int CopyFileClean()
clean env and others
Definition: test_CopyFile.c:43
static char * Src
Souce location.
Definition: test_CopyFile.c:24
static struct stat statSrc
Stat of source.
Definition: test_CopyFile.c:26
static char * Dst
Destination location.
Definition: test_CopyFile.c:25
void testCopyFileNormalDir()
copy directory
Definition: test_CopyFile.c:78
int CopyFileInit()
initialize
Definition: test_CopyFile.c:34
int exists
Default not exists.
Definition: run_tests.c:31
CU_TestInfo CopyFile_testcases[]
Copy test cases.