FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_Prune.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 *********************************************************************/
17 #include "run_tests.h"
22 /* local variables */
23 static char *Fname = "";
24 struct stat Stat;
25 static char *Dst = NULL;
26 static int Result = 0;
27 
28 
32 int PruneInit()
33 {
34  Dst = (char *)malloc(100);
35  return 0;
36 }
37 
42 {
43  free(Dst);
44  return 0;
45 }
46 
47 /* test functions */
48 
56 {
57  Fname = "../testdata/null_file";
58  deleteTmpFiles(NewDir);
59  strcpy(Dst, "./test-result/nullfile");
60  stat(Fname, &Stat);
61  CopyFile(Fname, Dst);
62  Result = Prune(Dst, Stat);
64  FO_ASSERT_EQUAL(exists, 0); // not existing
65  FO_ASSERT_EQUAL(Result, 1); // pruned
66 }
67 
75 {
76  Fname = "../testdata/test.ar";
77  deleteTmpFiles(NewDir);
78  strcpy(Dst, "./test-result/test.ar");
79  stat(Fname, &Stat);
80  CopyFile(Fname, Dst);
81  Result = Prune(Dst, Stat);
83  FO_ASSERT_EQUAL(exists, 1); // existing
84  FO_ASSERT_EQUAL(Result, 0); // not pruned
85 }
86 
87 #if 0
88 
94 void testPruneCharFile()
95 {
96  Fname = "../testdata/ext2file.fs";
97  stat(Fname, &Stat);
98  Result = Prune(Fname, Stat);
99  exists = file_dir_exists(Fname);
100  FO_ASSERT_EQUAL(exists, 0); // not existing
101  FO_ASSERT_EQUAL(Result, 1); // pruned
102 }
103 #endif
104 
105 
106 /* ************************************************************************** */
107 /* **** cunit test cases **************************************************** */
108 /* ************************************************************************** */
109 
110 CU_TestInfo Prune_testcases[] =
111 {
112  {"Prune: file size is 0", testPruneFileFileSzieIs0},
113  {"Prune: regular file, size > 0", testPruneRegFile},
114  CU_TEST_INFO_NULL
115 };
static int Result
Result of calls.
Definition: test_CopyFile.c:28
int file_dir_exists(char *path_name)
test if a file or directory exists
Definition: run_tests.c:136
void CopyFile(char *Source, char *Type, char *Name)
Definition: repcopyin.c:52
int PruneClean()
clean env and others
Definition: test_Prune.c:41
int PruneInit()
initialize
Definition: test_Prune.c:32
static char * Dst
Destination location.
Definition: test_CopyFile.c:25
char * NewDir
Test result directory.
Definition: run_tests.c:29
int Prune(char *Fname, struct stat Stat)
Given a filename and its stat, prune it.
Definition: utils.c:228
CU_TestInfo Prune_testcases[]
Prune() test cases.
Definition: test_Prune.c:110
void testPruneFileFileSzieIs0()
regular file, size is 0
Definition: test_Prune.c:55
int exists
Default not exists.
Definition: run_tests.c:31
void testPruneRegFile()
regular file, size is great than 0
Definition: test_Prune.c:74