-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_frame.c
127 lines (98 loc) · 2.89 KB
/
test_frame.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* This file is part of tframetest.
*
* Copyright (c) 2023 Tuxera Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
#include "profile.h"
#include "unittest.h"
#include "frame.h"
static const platform_t *frame_platform = NULL;
static frame_t *gen_default_frame(void)
{
profile_t prof;
prof = profile_get_by_index(1);
return frame_gen(frame_platform, prof);
}
int test_frame_gen(void)
{
frame_t *frm;
frm = gen_default_frame();
TEST_ASSERT(frm);
frame_destroy(frame_platform, frm);
return 0;
}
int test_frame_fill(void)
{
frame_t *frm;
size_t i;
frm = gen_default_frame();
TEST_ASSERT(frm);
/* Default fill with 't' */
for (i = 0; i < frm->size; i++)
TEST_ASSERT_EQI(i, ((unsigned char*)frm->data)[i], 't');
/* Test fill works */
TEST_ASSERT_EQ(frame_fill(frm, 0x42), frm->size);
for (i = 0; i < frm->size; i++)
TEST_ASSERT_EQI(i, ((unsigned char*)frm->data)[i], 0x42);
frame_destroy(frame_platform, frm);
return 0;
}
int test_frame_write_read(void)
{
frame_t *frm;
frame_t *frm_read;
size_t fw;
int fd;
frm = gen_default_frame();
frm_read = gen_default_frame();
TEST_ASSERT(frm);
TEST_ASSERT(frm_read);
TEST_ASSERT_EQ(frame_fill(frm, 0x42), frm->size);
TEST_ASSERT_EQ(((unsigned char*)frm->data)[0], 0x42);
TEST_ASSERT_EQ(((unsigned char*)frm_read->data)[0], 't');
fd = frame_platform->open("tst1", PLATFORM_OPEN_WRITE |
PLATFORM_OPEN_CREATE |
PLATFORM_OPEN_DIRECT, 0666);
fw = frame_write(frame_platform, fd, frm);
TEST_ASSERT_EQ(fw, frm->size);
frame_platform->close(fd);
TEST_ASSERT_EQ(((unsigned char*)frm_read->data)[0], 't');
fd = frame_platform->open("tst1", PLATFORM_OPEN_READ |
PLATFORM_OPEN_DIRECT, 0666);
fw = frame_read(frame_platform, fd, frm_read);
TEST_ASSERT_EQ(fw, frm->size);
TEST_ASSERT_EQ(((unsigned char*)frm->data)[0], 0x42);
TEST_ASSERT_EQ(((unsigned char*)frm_read->data)[0], 0x42);
frame_platform->close(fd);
frame_destroy(frame_platform, frm);
frame_destroy(frame_platform, frm_read);
return 0;
}
int test_frame(void)
{
TEST_INIT();
frame_platform = test_platform_get();
TEST(frame_gen);
TEST(frame_fill);
TEST(frame_write_read);
test_platform_finalize();
TEST_END();
}