File: DirTest.c

package info (click to toggle)
monit 1%3A5.4-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,028 kB
  • sloc: ansic: 22,062; sh: 10,070; yacc: 2,700; lex: 821; makefile: 260
file content (73 lines) | stat: -rw-r--r-- 2,129 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "Config.h"

#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <stdarg.h>

#include "Bootstrap.h"
#include "Str.h"
#include "system/Time.h"
#include "File.h"
#include "Dir.h"

/**
 * Dir.c unity tests. 
 */


int main(void) {
        Bootstrap(); // Need to initialize library
        
        printf("============> Start Dir Tests\n\n");
        
        printf("=> Test1: mkdir\n");
        {
                File_setUmask(022);
                assert(Dir_mkdir("X", 0));
                printf("\tResult: Dir X created with default perm = %#o\n", File_mod("X"));
                assert(File_mod("X") & 755);
                assert(Dir_mkdir("Y", 0700));
                printf("\tResult: Dir Y created with perm = %#o\n", File_mod("Y"));
                assert(File_mod("Y") & 700);
        }
        printf("=> Test1: OK\n\n");

        printf("=> Test2: chdir\n");
        {
                printf("\tResult: Changing working dir to X\n");
                assert(Dir_chdir("X"));
                printf("\tResult: Changing working dir to Y\n");
                assert(Dir_chdir("../Y"));
        }
        printf("=> Test2: OK\n\n");

        printf("=> Test3: getwd\n");
        {
                char cwd[STRLEN];
                assert(Dir_cwd(cwd, STRLEN));
                printf("\tResult: Current working dir is: %s\n", cwd);
                assert(Str_endsWith(cwd, "Y"));
                assert(Dir_chdir(".."));
                assert(Dir_cwd(cwd, STRLEN));
                printf("\tResult: Current working dir is: %s\n", cwd);
        }
        printf("=> Test3: OK\n\n");
                 
        printf("=> Test4: delete\n");
        {
                printf("\tResult: deleting dir X.. ");
                assert(Dir_delete("X"));
                printf("ok\n");
                printf("\tResult: deleting dir Y.. ");
                assert(Dir_delete("Y"));
                printf("ok\n");
        }
        printf("=> Test4: OK\n\n");
                 
        printf("============> Dir Tests: OK\n\n");
                 
        return 0;
}