Debian Codegraph @

storage/maria/libmarias3/tests/error.c

raw
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 * Copyright 2019 MariaDB Corporation Ab. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19
20 #include <yatl/lite.h>
21 #include <libmarias3/marias3.h>
22
23 /* Tests basic error handling */
24
25 int main(int argc, char *argv[])
26 {
27 uint8_t *data;
28 size_t length;
29 const char *errmsg;
30 uint8_t res;
31 ms3_st *ms3 = ms3_init("12345678901234567890",
32 "1234567890123456789012345678901234567890", "us-east-1", NULL);
33
34 (void) argc;
35 (void) argv;
36
37 // Enable here so cppcheck shows coverage
38 ms3_debug(1);
39 ASSERT_NOT_NULL(ms3);
40 errmsg = ms3_error(255);
41 ASSERT_STREQ(errmsg, "No such error code");
42 errmsg = ms3_error(0);
43 ASSERT_STREQ(errmsg, "No error");
44 res = ms3_get(ms3, "bad", "bad/file.txt", &data, &length);
45 printf("%d\n", res);
46 printf("%s\n", ms3_server_error(ms3));
47 ASSERT_EQ(res, MS3_ERR_AUTH); // Bad auth
48 free(data);
49 ms3_deinit(ms3);
50 ms3 = ms3_init("12345678901234567890",
51 "1234567890123456789012345678901234567890", "us-east-1", "bad-domain");
52 res = ms3_get(ms3, "bad", "bad/file.txt", &data, &length);
53 ASSERT_EQ(res, MS3_ERR_REQUEST_ERROR);
54 free(data);
55 ms3_deinit(ms3);
56 ms3_library_deinit();
57 return 0;
58 }