VirtualBox

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

Last change on this file since 57637 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

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