iPXE
mime_test.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26/** @file
27 *
28 * MIME image tests
29 *
30 */
31
32/* Forcibly enable assertions */
33#undef NDEBUG
34
35#include <ipxe/mime.h>
36#include <ipxe/test.h>
37#include "archive_test.h"
38
39/** "Hello world" */
40ARCHIVE_TEST ( hello_world, &mime_image_type, "hw.mime", NULL, "hw",
41 TEXTFILE ( "Content-Type: text/x-ipxe; charset=\"utf-8\"\r\n"
42 "MIME-Version: 1.0\r\n"
43 "Content-Transfer-Encoding: base64\r\n"
44 "Content-Disposition: attachment; filename=\"hw.ipxe\"\r\n"
45 "\r\n"
46 "IyFpcHhlCgplY2hvIEhlbGxvIHdvcmxkCnNoZWxsCg==\r\n" ),
47 TEXTFILE ( "#!ipxe\n"
48 "\n"
49 "echo Hello world\n"
50 "shell\n" ) );
51
52/** Multipart test */
53ARCHIVE_TEST ( multipart, &mime_image_type, "user-data", NULL, "user-data",
54 TEXTFILE ( "Content-Type: multipart/mixed; "
55 "boundary=\"===============5227682047807177400==\"\r\n"
56 "MIME-Version: 1.0\r\n"
57 "\r\n"
58 "--===============5227682047807177400==\r\n"
59 "Content-Type: text/cloud-config; charset=\"utf-8\"\r\n"
60 "MIME-Version: 1.0\r\n"
61 "Content-Transfer-Encoding: base64\r\n"
62 "Content-Disposition: attachment; filename=\"conf.yml\"\r\n"
63 "\r\n"
64 "LS0tCmNvbmZpZzoKICB0aGluZ3M6CiAgICAtIG9uZQogICAgLSB0d2\r\n"
65 "8KICBvdGhlcnRoaW5nOiAid29vaG9vIgo=\r\n"
66 "\r\n"
67 "--===============5227682047807177400==\r\n"
68 "Content-Type: text/x-ipxe; charset=\"utf-8\"\r\n"
69 "MIME-Version: 1.0\r\n"
70 "Content-Transfer-Encoding: base64\r\n"
71 "Content-Disposition: attachment; filename=\"hw.ipxe\"\r\n"
72 "\r\n"
73 "IyFpcHhlCgplY2hvIEhlbGxvIHdvcmxkCnNoZWxsCg==\r\n"
74 "\r\n"
75 "--===============5227682047807177400==--\r\n" ),
76 TEXTFILE ( "Content-Type: text/x-ipxe; charset=\"utf-8\"\r\n"
77 "MIME-Version: 1.0\r\n"
78 "Content-Transfer-Encoding: base64\r\n"
79 "Content-Disposition: attachment; filename=\"hw.ipxe\"\r\n"
80 "\r\n"
81 "IyFpcHhlCgplY2hvIEhlbGxvIHdvcmxkCnNoZWxsCg==\r\n"
82 "\r\n" ) );
83
84/** No explicit encoding */
85ARCHIVE_TEST ( no_encoding, &mime_image_type, "noenc.mime", NULL, "noenc",
86 TEXTFILE ( "Content-Type: text/x-ipxe; charset=\"utf-8\"\r\n"
87 "MIME-Version: 1.0\r\n"
88 "\r\n"
89 "#!ipxe\r\n"
90 "echo Default encoding\r\n" ),
91 TEXTFILE ( "#!ipxe\r\n"
92 "echo Default encoding\r\n" ) );
93
94/**
95 * Perform mime self-test
96 *
97 */
98static void mime_test_exec ( void ) {
99
100 archive_ok ( &hello_world );
101 archive_ok ( &multipart );
102 archive_ok ( &no_encoding );
103}
104
105/** MIME self-test */
106struct self_test mime_test __self_test = {
107 .name = "mime",
108 .exec = mime_test_exec,
109};
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
#define archive_ok(test)
Report an archive extraction test result.
#define ARCHIVE_TEST(name, TYPE, ARCHIVE_NAME, EXTRACT_NAME, EXPECTED_NAME, ARCHIVE, EXPECTED)
Define an archive extraction test.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
MIME format.
static void mime_test_exec(void)
Perform mime self-test.
Definition mime_test.c:98
A self-test set.
Definition test.h:15
Self-test infrastructure.
#define __self_test
Declare a self-test.
Definition test.h:32
#define TEXTFILE(text)
Define inline text file content.
Definition test.h:53