summaryrefslogtreecommitdiff
path: root/tests/cpp/include/variables/026-post-raw2.h
blob: d250dc82aa4ecdd47aa569a0edfb2df803814230 (plain)
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
74
75
76
/**
 *
 *  Test superglobal variables _POST
 *      026-post-raw2.phpt
 *
 */


#include <iostream>
#include <fstream>

/**
 *  Set up namespace
 */
namespace TestVariables {
    using namespace Php;


    /*
     * Test 
     */
    void post_raw2(void)
    {
        out << "name1 : "<< FILES["flnm"]["name"][0] << std::endl;
        out << "name2 : "<< FILES["flnm"]["name"][1] << std::endl;

        out << "type1 : "<< FILES["flnm"]["type"][0] << std::endl;
        out << "type2 : "<< FILES["flnm"]["type"][1] << std::endl;

        out << "error1 : "<< FILES["flnm"]["error"][0] << std::endl;
        out << "error2 : "<< FILES["flnm"]["error"][1] << std::endl;

        out << "size1 : "<< FILES["flnm"]["size"][0] << std::endl;
        out << "size2 : "<< FILES["flnm"]["size"][1] << std::endl;


        int length0 = FILES["flnm"]["size"][0];
        int length1 = FILES["flnm"]["size"][1];
        char *buffer0, *buffer1;
       
        std::ifstream file0, file1;
        std::string filename0 = FILES["flnm"]["tmp_name"][0];
        std::string filename1 = FILES["flnm"]["tmp_name"][1];

        file0.open(filename0, std::ios::in | std::ios::binary);
        file1.open(filename1, std::ios::in | std::ios::binary);

        if(!file0.is_open() || !file1.is_open()) {
            out << "Cannot open file." << std::endl;
            return;
        }
       
        //allocate memory
        buffer0 = new char[length0];
        buffer1 = new char[length1];
       
        //read data as a block to buffer
        file0.read(buffer0, length0);
        file1.read(buffer1, length1);
        file0.close();
        file1.close();
       
        out << "content1 : ";
        out.write(buffer0, length0);
        out << std::endl;
        out << "content2 : "<< buffer1 << std::endl;
       
        delete[] buffer0;
        delete[] buffer1;
    }

/**
 *  End of namespace
 */
}