File: test_opendir_partial.cpp

package info (click to toggle)
davix 0.8.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,184 kB
  • sloc: ansic: 164,612; cpp: 38,741; python: 17,726; perl: 14,124; sh: 13,458; xml: 3,567; makefile: 1,959; javascript: 885; pascal: 570; lisp: 7
file content (72 lines) | stat: -rw-r--r-- 1,688 bytes parent folder | download | duplicates (6)
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
#include "test_opendir_partial.h"


#include <davixcontext.hpp>
#include <memory>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <file/davposix.hpp>

#include "davix_test_lib.h"

/**
  Execute an incomplete readdir of a directory, and verify the correct closedir with the memory cleaning
*/

using namespace Davix;


#define MY_BUFFER_SIZE 65000




int main(int argc, char** argv){
    if( argc < 2){
        std::cout << "Usage  : " << std::endl;
       std::cout <<"\t" << argv[0] << " [url] [size_to_read]  " << std::endl;
        std::cout <<"\t" << argv[0] << " [url] [size_to_read] [CERTIFICATE_PATH] " << std::endl;
        return 0;
    }

    davix_set_log_level(DAVIX_LOG_ALL);
    int max_read= atoi(argv[2]);
    std::cout << " end of the dir number " << max_read << std::endl;

    DavixError* tmp_err=NULL;
    RequestParams  p;
    std::auto_ptr<Context> c( new Context());
    DavPosix pos(c.get());

    if(argc > 3){
        configure_grid_env(argv[3], p);
    }



    DAVIX_DIR* d = pos.opendir(&p, argv[1], &tmp_err);

    if(d){
        struct dirent * dir = NULL;
        int n= 0;
        do{
            dir= pos.readdir(d, &tmp_err);
            if(dir)
                std::cout << "N° " << n <<" file : " << dir->d_name << std::endl;
            n++;
        }while(dir!= NULL && max_read > n);
        if(dir == NULL){
            std::cout << " Normal end of the directory, too little directory, error in the test " << std::endl;
            return -3;
     }
   }

    pos.closedir(d, NULL);
    if(tmp_err){
        std::cout << " listing directory error "<< tmp_err->getErrMsg() << std::endl;
        return -1;
    }
    return 0;
}