VirtualBox

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

Last change on this file since 20606 was 20606, checked in by vboxsync, 15 years ago

IPRT/testcase: Use RTTestInitAndCreate.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/* $Id: tstRTS3.cpp 20606 2009-06-15 23:49:07Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Simple Storage Service (S3) Communication API
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <iprt/s3.h>
36#include <iprt/stream.h>
37#include <iprt/initterm.h>
38#include <iprt/err.h>
39#include <iprt/test.h>
40
41
42/*******************************************************************************
43* Defined Constants And Macros *
44*******************************************************************************/
45/* Manual configuration of this testcase */
46#define TSTS3_CREATEBUCKET
47#define TSTS3_PUTGETKEY
48//#define TSTS3_SHOWPROGRESS
49
50#ifdef TSTS3_CREATEBUCKET
51//# define TSTS3_CREATEBUCKET_BUCKETNAME "tstS3CreateBucket"
52# define TSTS3_CREATEBUCKET_BUCKETNAME "tt9"
53#endif /* TSTS3_CREATEBUCKET */
54
55#ifdef TSTS3_PUTGETKEY
56# define TSTS3_PUTGETKEY_BUCKETNAME "tstS3PutGetBucket"
57# define TSTS3_PUTGETKEY_KEYNAME "tstS3PutGetKey"
58# define TSTS3_PUTGETKEY_PUTFILE "tstS3"
59# define TSTS3_PUTGETKEY_GETFILE "tstS3_fetched"
60#endif /* TSTS3_PUTGETKEY */
61
62static int progress(unsigned uPercent, void *pvUser)
63{
64#ifdef TSTS3_SHOWPROGRESS
65 RTTestIPrintf(RTTESTLVL_ALWAYS, " Progress for %s - %d%% done.\n", (char*)pvUser, (int)uPercent);
66#endif /* TSTS3_SHOWPROGRESS */
67 return VINF_SUCCESS;
68}
69
70void fetchAllBuckets(RTS3 hS3)
71{
72 /* Fetch all available buckets */
73 RTTestIPrintf(RTTESTLVL_ALWAYS, " List all buckets...\n");
74 char pszTitle[] = "RTS3GetBuckets";
75 RTS3SetProgressCallback(hS3, progress, pszTitle);
76 PCRTS3BUCKETENTRY pBuckets = NULL;
77 int rc = RTS3GetBuckets(hS3, &pBuckets);
78 if (RT_SUCCESS(rc))
79 {
80 if (pBuckets)
81 {
82 PCRTS3BUCKETENTRY pTmpBuckets = pBuckets;
83 while (pBuckets)
84 {
85 RTTestIPrintf(RTTESTLVL_ALWAYS, " > %s, %s\n", pBuckets->pszName, pBuckets->pszCreationDate);
86 pBuckets = pBuckets->pNext;
87 }
88 RTS3BucketsDestroy(pTmpBuckets);
89 }
90 else
91 RTTestIPrintf(RTTESTLVL_ALWAYS, " > empty\n");
92 }
93 else
94 RTTestIFailed("RTS3GetBuckets -> %Rrc", rc);
95}
96
97void createBucket(RTS3 hS3, const char *pszBucketName)
98{
99 /* Create the bucket */
100 RTTestIPrintf(RTTESTLVL_ALWAYS, " Create bucket '%s'...\n", pszBucketName);
101 char pszTitle[] = "RTS3CreateBucket";
102 RTS3SetProgressCallback(hS3, progress, pszTitle);
103 int rc = RTS3CreateBucket(hS3, pszBucketName);
104 if (RT_FAILURE(rc))
105 RTTestIFailed("RTS3CreateBucket -> %Rrc", rc);
106}
107
108void deleteBucket(RTS3 hS3, const char *pszBucketName)
109{
110 /* Delete the bucket */
111 RTTestIPrintf(RTTESTLVL_ALWAYS, " Delete bucket '%s'...\n", pszBucketName);
112 char pszTitle[] = "RTS3DeleteBucket";
113 RTS3SetProgressCallback(hS3, progress, pszTitle);
114 int rc = RTS3DeleteBucket(hS3, pszBucketName);
115 if (RT_FAILURE(rc))
116 RTTestIFailed("RTS3DeleteBucket -> %Rrc", rc);
117}
118
119void fetchAllKeys(RTS3 hS3, const char *pszBucketName)
120{
121 /* Fetch all available keys of a specific bucket */
122 RTTestIPrintf(RTTESTLVL_ALWAYS, " List all keys of bucket '%s'...\n", pszBucketName);
123 PCRTS3KEYENTRY pKeys = NULL;
124 char pszTitle[] = "RTS3GetBucketKeys";
125 RTS3SetProgressCallback(hS3, progress, pszTitle);
126 int rc = RTS3GetBucketKeys(hS3, pszBucketName, &pKeys);
127 if (RT_SUCCESS(rc))
128 {
129 if (pKeys)
130 {
131 PCRTS3KEYENTRY pTmpKeys = pKeys;
132 while (pKeys)
133 {
134 RTTestIPrintf(RTTESTLVL_ALWAYS, " > %s, %s, %lu\n", pKeys->pszName, pKeys->pszLastModified, pKeys->cbFile);
135 pKeys = pKeys->pNext;
136 }
137 RTS3KeysDestroy(pTmpKeys);
138 }
139 else
140 RTTestIPrintf(RTTESTLVL_ALWAYS, " > empty\n");
141 }
142 else
143 RTTestIFailed("RTS3GetBucketKeys -> %Rrc", rc);
144}
145
146void deleteKey(RTS3 hS3, const char *pszBucketName, const char *pszKeyName)
147{
148 /* Delete the key */
149 RTTestIPrintf(RTTESTLVL_ALWAYS, " Delete key '%s' in bucket '%s'...\n", pszKeyName, pszBucketName);
150 char pszTitle[] = "RTS3DeleteKey";
151 RTS3SetProgressCallback(hS3, progress, pszTitle);
152 int rc = RTS3DeleteKey(hS3, pszBucketName, pszKeyName);
153 if (RT_FAILURE(rc))
154 RTTestIFailed("RTS3DeleteKey -> %Rrc", rc);
155}
156
157void getKey(RTS3 hS3, const char *pszBucketName, const char *pszKeyName, const char *pszFilename)
158{
159 /* Fetch the content of a key */
160 RTTestIPrintf(RTTESTLVL_ALWAYS, " Get key '%s' from bucket '%s' into '%s' ...\n", pszKeyName, pszBucketName, pszFilename);
161 char pszTitle[] = "RTS3GetKey";
162 RTS3SetProgressCallback(hS3, progress, pszTitle);
163 int rc = RTS3GetKey(hS3, pszBucketName, pszKeyName, pszFilename);
164 if (RT_FAILURE(rc))
165 RTTestIFailed("RTS3GetKey -> %Rrc", rc);
166}
167
168void putKey(RTS3 hS3, const char *pszBucketName, const char *pszKeyName, const char *pszFilename)
169{
170 /* Fetch the content of a key */
171 RTTestIPrintf(RTTESTLVL_ALWAYS, " Put '%s' into key '%s' in bucket '%s' ...\n", pszFilename, pszKeyName, pszBucketName);
172 char pszTitle[] = "RTS3PutKey";
173 RTS3SetProgressCallback(hS3, progress, pszTitle);
174 int rc = RTS3PutKey(hS3, pszBucketName, pszKeyName, pszFilename);
175 if (RT_FAILURE(rc))
176 RTTestIFailed("RTS3PutKey -> %Rrc", rc);
177}
178
179int main(int argc, char **argv)
180{
181 /*
182 * Initialize IPRT and create the test.
183 */
184 RTTEST hTest;
185 int rc = RTTestInitAndCreate("tstRTS3", &hTest);
186 if (rc)
187 return rc;
188 RTTestBanner(hTest);
189
190 /*
191 * If no args, display usage.
192 */
193 if (argc <= 2)
194 {
195 RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "Syntax: %s [Access Key] [Secret Key]\n", argv[0]);
196 return RTTestSkipAndDestroy(hTest, "Missing required arguments\n");
197 }
198
199 RTTestSubF(hTest, "Create S3");
200 RTS3 hS3;
201 rc = RTS3Create(&hS3, argv[1], argv[2], "object.storage.network.com", "tstS3-agent/1.0");
202 if (RT_FAILURE(rc))
203 {
204 RTTestIFailed("RTS3Create -> %Rrc", rc);
205 return RTTestSummaryAndDestroy(hTest);
206 }
207
208 RTTestSub(hTest, "Fetch buckets");
209 fetchAllBuckets(hS3);
210 RTTestSub(hTest, "Fetch keys");
211 fetchAllKeys(hS3, "bla");
212
213#ifdef TSTS3_CREATEBUCKET
214 RTTestSub(hTest, "Create bucket");
215 createBucket(hS3, TSTS3_CREATEBUCKET_BUCKETNAME);
216 fetchAllBuckets(hS3);
217 deleteBucket(hS3, TSTS3_CREATEBUCKET_BUCKETNAME);
218 fetchAllBuckets(hS3);
219#endif /* TSTS3_CREATEBUCKET */
220
221
222#ifdef TSTS3_PUTGETKEY
223 RTTestSub(hTest, "Put key");
224 createBucket(hS3, TSTS3_PUTGETKEY_BUCKETNAME);
225 putKey(hS3, TSTS3_PUTGETKEY_BUCKETNAME, TSTS3_PUTGETKEY_KEYNAME, TSTS3_PUTGETKEY_PUTFILE);
226 fetchAllKeys(hS3, TSTS3_PUTGETKEY_BUCKETNAME);
227 getKey(hS3, TSTS3_PUTGETKEY_BUCKETNAME, TSTS3_PUTGETKEY_KEYNAME, TSTS3_PUTGETKEY_GETFILE);
228 deleteKey(hS3, TSTS3_PUTGETKEY_BUCKETNAME, TSTS3_PUTGETKEY_KEYNAME);
229 fetchAllKeys(hS3, TSTS3_PUTGETKEY_BUCKETNAME);
230 deleteBucket(hS3, TSTS3_PUTGETKEY_BUCKETNAME);
231#endif /* TSTS3_PUTGETKEY */
232
233 RTS3Destroy(hS3);
234
235 /*
236 * Summary
237 */
238 return RTTestSummaryAndDestroy(hTest);
239}
240
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