VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTS3.cpp@ 78393

Last change on this file since 78393 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
1/* $Id: tstRTS3.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Simple Storage Service (S3) Communication API
4 */
5
6/*
7 * Copyright (C) 2009-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/s3.h>
32#include <iprt/stream.h>
33#include <iprt/initterm.h>
34#include <iprt/errcore.h>
35#include <iprt/test.h>
36
37
38/*********************************************************************************************************************************
39* Defined Constants And Macros *
40*********************************************************************************************************************************/
41/* Manual configuration of this testcase */
42#define TSTS3_CREATEBUCKET
43#define TSTS3_PUTGETKEY
44//#define TSTS3_SHOWPROGRESS
45
46#ifdef TSTS3_CREATEBUCKET
47//# define TSTS3_CREATEBUCKET_BUCKETNAME "tstS3CreateBucket"
48# define TSTS3_CREATEBUCKET_BUCKETNAME "tt9"
49#endif /* TSTS3_CREATEBUCKET */
50
51#ifdef TSTS3_PUTGETKEY
52# define TSTS3_PUTGETKEY_BUCKETNAME "tstS3PutGetBucket"
53# define TSTS3_PUTGETKEY_KEYNAME "tstS3PutGetKey"
54# define TSTS3_PUTGETKEY_PUTFILE "tstS3"
55# define TSTS3_PUTGETKEY_GETFILE "tstS3_fetched"
56#endif /* TSTS3_PUTGETKEY */
57
58static DECLCALLBACK(int) progress(unsigned uPercent, void *pvUser)
59{
60#ifdef TSTS3_SHOWPROGRESS
61 RTTestIPrintf(RTTESTLVL_ALWAYS, " Progress for %s - %d%% done.\n", (char*)pvUser, (int)uPercent);
62#else
63 RT_NOREF2(uPercent, pvUser);
64#endif
65 return VINF_SUCCESS;
66}
67
68void fetchAllBuckets(RTS3 hS3)
69{
70 /* Fetch all available buckets */
71 RTTestIPrintf(RTTESTLVL_ALWAYS, " List all buckets...\n");
72 char pszTitle[] = "RTS3GetBuckets";
73 RTS3SetProgressCallback(hS3, progress, pszTitle);
74 PCRTS3BUCKETENTRY pBuckets = NULL;
75 int rc = RTS3GetBuckets(hS3, &pBuckets);
76 if (RT_SUCCESS(rc))
77 {
78 if (pBuckets)
79 {
80 PCRTS3BUCKETENTRY pTmpBuckets = pBuckets;
81 while (pBuckets)
82 {
83 RTTestIPrintf(RTTESTLVL_ALWAYS, " > %s, %s\n", pBuckets->pszName, pBuckets->pszCreationDate);
84 pBuckets = pBuckets->pNext;
85 }
86 RTS3BucketsDestroy(pTmpBuckets);
87 }
88 else
89 RTTestIPrintf(RTTESTLVL_ALWAYS, " > empty\n");
90 }
91 else
92 RTTestIFailed("RTS3GetBuckets -> %Rrc", rc);
93}
94
95void createBucket(RTS3 hS3, const char *pszBucketName)
96{
97 /* Create the bucket */
98 RTTestIPrintf(RTTESTLVL_ALWAYS, " Create bucket '%s'...\n", pszBucketName);
99 char pszTitle[] = "RTS3CreateBucket";
100 RTS3SetProgressCallback(hS3, progress, pszTitle);
101 int rc = RTS3CreateBucket(hS3, pszBucketName);
102 if (RT_FAILURE(rc))
103 RTTestIFailed("RTS3CreateBucket -> %Rrc", rc);
104}
105
106void deleteBucket(RTS3 hS3, const char *pszBucketName)
107{
108 /* Delete the bucket */
109 RTTestIPrintf(RTTESTLVL_ALWAYS, " Delete bucket '%s'...\n", pszBucketName);
110 char pszTitle[] = "RTS3DeleteBucket";
111 RTS3SetProgressCallback(hS3, progress, pszTitle);
112 int rc = RTS3DeleteBucket(hS3, pszBucketName);
113 if (RT_FAILURE(rc))
114 RTTestIFailed("RTS3DeleteBucket -> %Rrc", rc);
115}
116
117void fetchAllKeys(RTS3 hS3, const char *pszBucketName)
118{
119 /* Fetch all available keys of a specific bucket */
120 RTTestIPrintf(RTTESTLVL_ALWAYS, " List all keys of bucket '%s'...\n", pszBucketName);
121 PCRTS3KEYENTRY pKeys = NULL;
122 char pszTitle[] = "RTS3GetBucketKeys";
123 RTS3SetProgressCallback(hS3, progress, pszTitle);
124 int rc = RTS3GetBucketKeys(hS3, pszBucketName, &pKeys);
125 if (RT_SUCCESS(rc))
126 {
127 if (pKeys)
128 {
129 PCRTS3KEYENTRY pTmpKeys = pKeys;
130 while (pKeys)
131 {
132 RTTestIPrintf(RTTESTLVL_ALWAYS, " > %s, %s, %lu\n", pKeys->pszName, pKeys->pszLastModified, pKeys->cbFile);
133 pKeys = pKeys->pNext;
134 }
135 RTS3KeysDestroy(pTmpKeys);
136 }
137 else
138 RTTestIPrintf(RTTESTLVL_ALWAYS, " > empty\n");
139 }
140 else
141 RTTestIFailed("RTS3GetBucketKeys -> %Rrc", rc);
142}
143
144void deleteKey(RTS3 hS3, const char *pszBucketName, const char *pszKeyName)
145{
146 /* Delete the key */
147 RTTestIPrintf(RTTESTLVL_ALWAYS, " Delete key '%s' in bucket '%s'...\n", pszKeyName, pszBucketName);
148 char pszTitle[] = "RTS3DeleteKey";
149 RTS3SetProgressCallback(hS3, progress, pszTitle);
150 int rc = RTS3DeleteKey(hS3, pszBucketName, pszKeyName);
151 if (RT_FAILURE(rc))
152 RTTestIFailed("RTS3DeleteKey -> %Rrc", rc);
153}
154
155void getKey(RTS3 hS3, const char *pszBucketName, const char *pszKeyName, const char *pszFilename)
156{
157 /* Fetch the content of a key */
158 RTTestIPrintf(RTTESTLVL_ALWAYS, " Get key '%s' from bucket '%s' into '%s' ...\n", pszKeyName, pszBucketName, pszFilename);
159 char pszTitle[] = "RTS3GetKey";
160 RTS3SetProgressCallback(hS3, progress, pszTitle);
161 int rc = RTS3GetKey(hS3, pszBucketName, pszKeyName, pszFilename);
162 if (RT_FAILURE(rc))
163 RTTestIFailed("RTS3GetKey -> %Rrc", rc);
164}
165
166void putKey(RTS3 hS3, const char *pszBucketName, const char *pszKeyName, const char *pszFilename)
167{
168 /* Fetch the content of a key */
169 RTTestIPrintf(RTTESTLVL_ALWAYS, " Put '%s' into key '%s' in bucket '%s' ...\n", pszFilename, pszKeyName, pszBucketName);
170 char pszTitle[] = "RTS3PutKey";
171 RTS3SetProgressCallback(hS3, progress, pszTitle);
172 int rc = RTS3PutKey(hS3, pszBucketName, pszKeyName, pszFilename);
173 if (RT_FAILURE(rc))
174 RTTestIFailed("RTS3PutKey -> %Rrc", rc);
175}
176
177int main(int argc, char **argv)
178{
179 /*
180 * Initialize IPRT and create the test.
181 */
182 RTTEST hTest;
183 int rc = RTTestInitAndCreate("tstRTS3", &hTest);
184 if (rc)
185 return rc;
186 RTTestBanner(hTest);
187
188 /*
189 * If no args, display usage.
190 */
191 if (argc <= 2)
192 {
193 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "Syntax: %s [Access Key] [Secret Key]\n", argv[0]);
194 return RTTestSkipAndDestroy(hTest, "Missing required arguments\n");
195 }
196
197 RTTestSubF(hTest, "Create S3");
198 RTS3 hS3;
199 rc = RTS3Create(&hS3, argv[1], argv[2], "object.storage.network.com", "tstS3-agent/1.0");
200 if (RT_FAILURE(rc))
201 {
202 RTTestIFailed("RTS3Create -> %Rrc", rc);
203 return RTTestSummaryAndDestroy(hTest);
204 }
205
206 RTTestSub(hTest, "Fetch buckets");
207 fetchAllBuckets(hS3);
208 RTTestSub(hTest, "Fetch keys");
209 fetchAllKeys(hS3, "bla");
210
211#ifdef TSTS3_CREATEBUCKET
212 RTTestSub(hTest, "Create bucket");
213 createBucket(hS3, TSTS3_CREATEBUCKET_BUCKETNAME);
214 fetchAllBuckets(hS3);
215 deleteBucket(hS3, TSTS3_CREATEBUCKET_BUCKETNAME);
216 fetchAllBuckets(hS3);
217#endif /* TSTS3_CREATEBUCKET */
218
219
220#ifdef TSTS3_PUTGETKEY
221 RTTestSub(hTest, "Put key");
222 createBucket(hS3, TSTS3_PUTGETKEY_BUCKETNAME);
223 putKey(hS3, TSTS3_PUTGETKEY_BUCKETNAME, TSTS3_PUTGETKEY_KEYNAME, TSTS3_PUTGETKEY_PUTFILE);
224 fetchAllKeys(hS3, TSTS3_PUTGETKEY_BUCKETNAME);
225 getKey(hS3, TSTS3_PUTGETKEY_BUCKETNAME, TSTS3_PUTGETKEY_KEYNAME, TSTS3_PUTGETKEY_GETFILE);
226 deleteKey(hS3, TSTS3_PUTGETKEY_BUCKETNAME, TSTS3_PUTGETKEY_KEYNAME);
227 fetchAllKeys(hS3, TSTS3_PUTGETKEY_BUCKETNAME);
228 deleteBucket(hS3, TSTS3_PUTGETKEY_BUCKETNAME);
229#endif /* TSTS3_PUTGETKEY */
230
231 RTS3Destroy(hS3);
232
233 /*
234 * Summary
235 */
236 return RTTestSummaryAndDestroy(hTest);
237}
238
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette