VirtualBox

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

Last change on this file since 56978 was 56290, checked in by vboxsync, 9 years ago

IPRT: Updated (C) year.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/* $Id: tstRTManifest.cpp 56290 2015-06-09 14:01:31Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Manifest files.
4 */
5
6/*
7 * Copyright (C) 2010-2015 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
39
40/**
41 * Basic API checks.
42 */
43static void tst1(void)
44{
45 RTTestISub("Manifest creation");
46
47 size_t cbSize = 0;
48 size_t iFailed = 0;
49
50 /*
51 * test1.txt = "This is a test text."
52 * test2.txt = "Another test text."
53 */
54 static RTMANIFESTTEST /*const*/ s_aFiles[] = /** @todo API misdesign, this should be const. */
55 {
56 { "test1.txt", "794a8cc644b318ae6461aeea62915e399e441e8" },
57 { "test2.txt", "f17393902ee94c1e8bbd4bf417cdc70051feca00" }
58 };
59 static const char s_szTestPattern[] =
60 "SHA1 (test1.txt)= 794a8cc644b318ae6461aeea62915e399e441e8\n"
61 "SHA1 (test2.txt)= f17393902ee94c1e8bbd4bf417cdc70051feca00\n"
62 ;
63
64 void *pvBuf = NULL;
65 RTTESTI_CHECK_RC_RETV(RTManifestWriteFilesBuf(&pvBuf, &cbSize, RTDIGESTTYPE_SHA1, s_aFiles, 2), VINF_SUCCESS);
66
67 /* Check returned memory size */
68 RTTESTI_CHECK_RETV(cbSize == strlen(s_szTestPattern));
69
70 /* Check for correct manifest file content */
71 RTTESTI_CHECK(memcmp(pvBuf, s_szTestPattern, cbSize) == 0);
72
73 RTTestISub("Manifest verify");
74 RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 2, 0), VINF_SUCCESS);
75
76 /* To little files to check */
77 RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 1, 0), VERR_MANIFEST_FILE_MISMATCH);
78
79 /* Make the digest type invalid */
80 ((char*)pvBuf)[0] = 'L';
81 RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 2, 0), VERR_MANIFEST_UNSUPPORTED_DIGEST_TYPE);
82 ((char*)pvBuf)[0] = 'S'; /* Restore */
83
84 /* Make the file name invalid */
85 ((char*)pvBuf)[8] = 'z';
86 RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 2, 0), VERR_MANIFEST_FILE_MISMATCH);
87 ((char*)pvBuf)[8] = 's'; /* Restore */
88
89 /* Make the second digest invalid */
90 ((char*)pvBuf)[99] = '0';
91 RTTESTI_CHECK_RC(RTManifestVerifyFilesBuf(pvBuf, cbSize, s_aFiles, 2, &iFailed), VERR_MANIFEST_DIGEST_MISMATCH);
92 RTTESTI_CHECK(iFailed == 1);
93
94 /* Cleanup */
95 RTMemFree(pvBuf);
96}
97
98
99int main()
100{
101 RTTEST hTest;
102 int rc = RTTestInitAndCreate("tstRTManifest", &hTest);
103 if (rc)
104 return rc;
105 RTTestBanner(hTest);
106
107 tst1();
108
109 return RTTestSummaryAndDestroy(hTest);
110}
111
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