| 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 GET with a small buffer */ |
| 24 |
|
| 25 |
int main(int argc, char *argv[]) |
| 26 |
{ |
| 27 |
int res; |
| 28 |
uint8_t *data; |
| 29 |
size_t length; |
| 30 |
size_t new_buffer_size; |
| 31 |
ms3_st *ms3; |
| 32 |
char *test_string = malloc(64 * 1024); |
| 33 |
char *s3key = getenv("S3KEY"); |
| 34 |
char *s3secret = getenv("S3SECRET"); |
| 35 |
char *s3region = getenv("S3REGION"); |
| 36 |
char *s3bucket = getenv("S3BUCKET"); |
| 37 |
char *s3host = getenv("S3HOST"); |
| 38 |
char *s3noverify = getenv("S3NOVERIFY"); |
| 39 |
char *s3usehttp = getenv("S3USEHTTP"); |
| 40 |
char *s3port = getenv("S3PORT"); |
| 41 |
memset(test_string, 'a', 64 * 1024); |
| 42 |
|
| 43 |
SKIP_IF_(!s3key, "Environemnt variable S3KEY missing"); |
| 44 |
SKIP_IF_(!s3secret, "Environemnt variable S3SECRET missing"); |
| 45 |
SKIP_IF_(!s3region, "Environemnt variable S3REGION missing"); |
| 46 |
SKIP_IF_(!s3bucket, "Environemnt variable S3BUCKET missing"); |
| 47 |
|
| 48 |
(void) argc; |
| 49 |
(void) argv; |
| 50 |
|
| 51 |
ms3_library_init(); |
| 52 |
ms3 = ms3_init(s3key, s3secret, s3region, s3host); |
| 53 |
|
| 54 |
if (s3noverify && !strcmp(s3noverify, "1")) |
| 55 |
{ |
| 56 |
ms3_set_option(ms3, MS3_OPT_DISABLE_SSL_VERIFY, NULL); |
| 57 |
} |
| 58 |
|
| 59 |
if (s3usehttp && !strcmp(s3usehttp, "1")) |
| 60 |
{ |
| 61 |
ms3_set_option(ms3, MS3_OPT_USE_HTTP, NULL); |
| 62 |
} |
| 63 |
|
| 64 |
if (s3port) |
| 65 |
{ |
| 66 |
int port = atoi(s3port); |
| 67 |
ms3_set_option(ms3, MS3_OPT_PORT_NUMBER, &port); |
| 68 |
} |
| 69 |
|
| 70 |
// ms3_debug(true); |
| 71 |
ASSERT_NOT_NULL(ms3); |
| 72 |
|
| 73 |
res = ms3_put(ms3, s3bucket, "test/small_buffer.dat", |
| 74 |
(const uint8_t *)test_string, |
| 75 |
64 * 1024); |
| 76 |
ASSERT_EQ_(res, 0, "Result: %u", res); |
| 77 |
new_buffer_size = 64 * 1024; |
| 78 |
res = ms3_set_option(ms3, MS3_OPT_BUFFER_CHUNK_SIZE, &new_buffer_size); |
| 79 |
ASSERT_EQ_(res, 0, "Result: %u", res); |
| 80 |
res = ms3_get(ms3, s3bucket, "test/small_buffer.dat", &data, &length); |
| 81 |
ASSERT_EQ_(res, 0, "Result: %u", res); |
| 82 |
ASSERT_EQ(length, 64 * 1024); |
| 83 |
ms3_free(data); |
| 84 |
|
| 85 |
new_buffer_size = 1024; |
| 86 |
res = ms3_set_option(ms3, MS3_OPT_BUFFER_CHUNK_SIZE, &new_buffer_size); |
| 87 |
ASSERT_EQ_(res, 0, "Result: %u", res); |
| 88 |
res = ms3_get(ms3, s3bucket, "test/small_buffer.dat", &data, &length); |
| 89 |
ASSERT_EQ_(res, 0, "Result: %u", res); |
| 90 |
ASSERT_EQ(length, 64 * 1024); |
| 91 |
res = ms3_delete(ms3, s3bucket, "test/small_buffer.dat"); |
| 92 |
ASSERT_EQ_(res, 0, "Result: %u", res); |
| 93 |
free(test_string); |
| 94 |
ms3_free(data); |
| 95 |
ms3_deinit(ms3); |
| 96 |
ms3_library_deinit(); |
| 97 |
return 0; |
| 98 |
} |