root/branches/windows-client/src/client/windows/client-test/create.c @ 8722

Revision 8722, 1.9 KB (checked in by sampson, 2 years ago)

Coding Windows tests

  • Property svn:executable set to *
Line 
1/* Copyright (C) 2011 Omnibond, LLC
2   Client -- creation tests */
3
4#include <stdlib.h>
5#include <stdio.h>
6#include <string.h>
7#include <direct.h>
8
9#include "test-support.h"
10
11void create_dir_cleanup(char *dir)
12{
13    _rmdir(dir);
14}
15
16char randchar()
17{
18    return rand() % 26 + 'a';
19}
20
21int create_dir(op_options *options, int fatal)
22{
23    int code;
24    char *dir;
25
26    /* create a directory in the root dir */
27    dir = randdir(options->root_dir);
28    _mkdir(dir);
29    code = errno;
30
31    report_result(options, "create-dir", RESULT_SUCCESS, 0, OPER_EQUAL, code);
32
33    create_dir_cleanup(dir);
34
35    free(dir);
36
37    if (code != 0 && fatal)
38        return CODE_FATAL;
39
40    return 0;
41}
42
43#define MAX_SIZE    256
44
45int create_subdir(op_options *options, int fatal)
46{
47    int rem_size = MAX_SIZE, dir_size, i,
48        code = 0;
49    char path[MAX_SIZE*2], dir[9];
50
51    /* copy root into path */
52    strcpy(path, options->root_dir);
53    /* rem_size -= strlen(options->root_dir); */
54    /* add backslash if necessary */
55    if (strlen(options->root_dir) &&
56        options->root_dir[strlen(options->root_dir)-1] != '\\')
57    {
58        strcat(path, "\\");
59        /* rem_size--; */
60    }
61
62    /* note--root dir is not included in the path size */
63
64    while (rem_size > 0 && code == 0)
65    {
66        /* generate subdir */
67        dir_size = rem_size > 8 ? 8 : rem_size;
68        for (i = 0; i < dir_size-1; i++)
69            dir[i] = randchar();
70        dir[dir_size-1] = '\\';
71        dir[dir_size] = '\0';
72
73        /* append the path */
74        strcat(path, dir);
75
76        /* create the sub-directory */
77        _mkdir(path);
78        code = errno;
79
80        rem_size -= dir_size;
81    }
82
83    report_result(options, "create-subdir", RESULT_SUCCESS, 0, OPER_EQUAL, code);
84
85    if (code != 0 && fatal)
86        return CODE_FATAL;
87
88    return 0;
89}
Note: See TracBrowser for help on using the browser.