FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_Prune.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 */
6 #include "run_tests.h"
11 /* local variables */
12 static char *Fname = "";
13 struct stat Statf;
14 static char *Dst = NULL;
15 static int Result = 0;
16 
17 
21 int PruneInit()
22 {
23  Dst = (char *)malloc(100);
24  return 0;
25 }
26 
31 {
32  free(Dst);
33  return 0;
34 }
35 
36 /* test functions */
37 
45 {
46  Fname = "../testdata/null_file";
47  deleteTmpFiles(NewDir);
48  strcpy(Dst, "./test-result/nullfile");
49  stat(Fname, &Statf);
50  CopyFile(Fname, Dst);
51  Result = Prune(Dst, Statf);
53  FO_ASSERT_EQUAL(exists, 0); // not existing
54  FO_ASSERT_EQUAL(Result, 1); // pruned
55 }
56 
64 {
65  Fname = "../testdata/test.ar";
66  deleteTmpFiles(NewDir);
67  strcpy(Dst, "./test-result/test.ar");
68  stat(Fname, &Statf);
69  CopyFile(Fname, Dst);
70  Result = Prune(Dst, Statf);
72  FO_ASSERT_EQUAL(exists, 1); // existing
73  FO_ASSERT_EQUAL(Result, 0); // not pruned
74 }
75 
76 #if 0
83 void testPruneCharFile()
84 {
85  Fname = "../testdata/ext2file.fs";
86  stat(Fname, &Statf);
87  Result = Prune(Fname, Statf);
88  exists = file_dir_exists(Fname);
89  FO_ASSERT_EQUAL(exists, 0); // not existing
90  FO_ASSERT_EQUAL(Result, 1); // pruned
91 }
92 #endif
93 
94 
95 /* ************************************************************************** */
96 /* **** cunit test cases **************************************************** */
97 /* ************************************************************************** */
98 
99 CU_TestInfo Prune_testcases[] =
100 {
101  {"Prune: file size is 0", testPruneFileFileSzieIs0},
102  {"Prune: regular file, size > 0", testPruneRegFile},
103  CU_TEST_INFO_NULL
104 };
void CopyFile(char *Source, char *Type, char *Name)
Definition: repcopyin.c:39
static int Result
Result of calls.
Definition: test_CopyFile.c:17
static char * Dst
Destination location.
Definition: test_CopyFile.c:14
void testPruneRegFile()
regular file, size is great than 0
Definition: test_Prune.c:63
CU_TestInfo Prune_testcases[]
Prune() test cases.
Definition: test_Prune.c:99
void testPruneFileFileSzieIs0()
regular file, size is 0
Definition: test_Prune.c:44
int PruneInit()
initialize
Definition: test_Prune.c:21
int PruneClean()
clean env and others
Definition: test_Prune.c:30
int Prune(char *Fname, struct stat Stat)
Given a filename and its stat, prune it.
Definition: utils.c:217
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
char * NewDir
Test result directory.
Definition: run_tests.c:18