VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTManifest.cpp@ 33867

Last change on this file since 33867 was 33290, checked in by vboxsync, 14 years ago

Runtime: add a simple testcase for RTManifest

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: tstRTManifest.cpp 33290 2010-10-21 10:20:17Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Manifest files.
4 */
5
6/*
7 * Copyright (C) 2010 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* Header Files *
29*******************************************************************************/
30#include <iprt/manifest.h>
31
32#include <iprt/string.h>
33#include <iprt/err.h>
34#include <iprt/mem.h>
35#include <iprt/test.h>
36
37/**
38 * Basic API checks.
39 */
40static void tst1(void)
41{
42 void *pvBuf = NULL;
43 size_t cbSize = 0;
44 size_t iFailed = 0;
45
46 /*
47 * test1.txt = "This is a test text."
48 * test2.txt = "Another test text."
49 */
50 RTMANIFESTTEST paFiles[] = { { "test1.txt", "794a8cc644b318ae6461aeea62915e399e441e8" }, { "test2.txt", "f17393902ee94c1e8bbd4bf417cdc70051feca00" } };
51 const char pcszTestPattern[] = "SHA1 (test1.txt)= 794a8cc644b318ae6461aeea62915e399e441e8\nSHA1 (test2.txt)= f17393902ee94c1e8bbd4bf417cdc70051feca00\n";
52
53 RTTestISub("Manifest creation");
54 RTTESTI_CHECK_RC_RETV(RTManifestWriteFilesBuf(&pvBuf, &cbSize, paFiles, 2), VINF_SUCCESS);
55 /* Check returned memory size */
56 RTTESTI_CHECK_RETV(cbSize == strlen(pcszTestPattern));
57 /* Check for correct manifest file content */
58 RTTESTI_CHECK(memcmp(pvBuf, pcszTestPattern, cbSize) == 0);
59
60 RTTestISub("Manifest verify");
61 RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, paFiles, 2, 0), VINF_SUCCESS);
62 /* To little files to check */
63 RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, paFiles, 1, 0), VERR_MANIFEST_FILE_MISMATCH);
64 /* Make the digest type invalid */
65 ((char*)pvBuf)[0] = 'L';
66 RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, paFiles, 2, 0), VERR_MANIFEST_UNSUPPORTED_DIGEST_TYPE);
67 ((char*)pvBuf)[0] = 'S'; /* Restore */
68 /* Make the file name invalid */
69 ((char*)pvBuf)[8] = 'z';
70 RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, paFiles, 2, 0), VERR_MANIFEST_FILE_MISMATCH);
71 ((char*)pvBuf)[8] = 's'; /* Restore */
72 /* Make the second digest invalid */
73 ((char*)pvBuf)[99] = '0';
74 RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, paFiles, 2, &iFailed), VERR_MANIFEST_DIGEST_MISMATCH);
75 RTTESTI_CHECK(iFailed == 1);
76
77 /* Cleanup */
78 if (pvBuf)
79 RTMemFree(pvBuf);
80}
81
82
83int main()
84{
85 RTTEST hTest;
86 int rc = RTTestInitAndCreate("tstRTManifest", &hTest);
87 if (rc)
88 return rc;
89 RTTestBanner(hTest);
90
91 tst1();
92
93 return RTTestSummaryAndDestroy(hTest);
94}
95
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