~stolowski/thumbnailer/more-debug

« back to all changes in this revision

Viewing changes to tests/file_io/file_io_test.cpp

  • Committer: CI Train Bot
  • Author(s): Michi Henning
  • Date: 2016-01-07 04:36:36 UTC
  • mfrom: (129.1.22 landing-12.15)
  • Revision ID: ci-train-bot@canonical.com-20160107043636-xbao3rktj4uf3u0f
Merge changes from devel to trunk for landing.
Approved by: Michi Henning, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
{
32
32
    string in_file = TESTDATADIR "/testimage.jpg";
33
33
    struct stat st;
34
 
    cerr << "in_file: " << in_file << endl;
35
34
    ASSERT_NE(-1, stat(in_file.c_str(), &st));
36
35
 
37
36
    string data = read_file(in_file);
39
38
 
40
39
    string out_file = TESTBINDIR "/testimage.jpg";
41
40
    write_file(out_file, data);
 
41
    string data2 = read_file(out_file);
 
42
    ASSERT_EQ(data, data2);
 
43
 
 
44
    auto ba = QByteArray::fromStdString(data);
 
45
    write_file(out_file, ba);
 
46
    data2 = read_file(out_file);
 
47
    ASSERT_EQ(data, data2);
42
48
 
43
49
    string cmd = "cmp " + in_file + " " + out_file;
44
50
    int rc = system(cmd.c_str());
63
69
    ASSERT_NE(-1, in_fd);
64
70
    out_file = TESTBINDIR "/out.jpg";
65
71
    unlink(out_file.c_str());
66
 
    write_file(in_fd, out_file);
 
72
    write_file(out_file, in_fd);
67
73
    close(in_fd);
68
74
    cmd = "cmp " + in_file + " " + out_file;
69
75
    rc = system(cmd.c_str());
93
99
    mkdir(dir.c_str(), 0700);  // If dir doesn't exist, create it.
94
100
 
95
101
    string out_file = dir + "/no_perm";
96
 
    write_file(out_file, "");
 
102
    write_file(out_file, string());
97
103
 
98
104
    chmod(dir.c_str(), 0500);  // Remove write permission on directory
99
105
 
100
106
    try
101
107
    {
102
 
        write_file(out_file, "");
 
108
        write_file(out_file, string());
103
109
        chmod(dir.c_str(), 0700);
104
110
        FAIL();
105
111
    }
138
144
    {
139
145
        int fd = open("/dev/zero", O_WRONLY);
140
146
        ASSERT_NE(-1, fd);
141
 
        write_file(fd, "no_such_dir/no_such_file");
 
147
        write_file("no_such_dir/no_such_file", fd);
142
148
        FAIL();
143
149
    }
144
150
    catch (runtime_error const& e)