-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
173 lines (153 loc) · 6.59 KB
/
example.c
File metadata and controls
173 lines (153 loc) · 6.59 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/***************************************************************************
* Copyright(C)2014-2015 by FlyLu <Linch.Embedded@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser 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 Lesser General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/*============================ INCLUDES ======================================*/
#include ".\history.h"
#include "stdio.h"
void history_item_test(void)
{
history_item_t tHistory, *ptHistoryPtr;
int j = HISTORY_ITEM_MAX_COUNT - 1;
init_history();
printf("History Item Max Count -> %d\r\n", HISTORY_ITEM_MAX_COUNT);
printf("--------------------------------------\r\n");
do {
if (HISTORY_ITEM_MAX_COUNT - 1 == j) {
printf("\r\nFrist Print Result\r\n");
} else if (HISTORY_ITEM_MAX_COUNT == j) {
printf("\r\nSecond Print Result\r\n");
} else if (HISTORY_ITEM_MAX_COUNT + 1 == j){
printf("\r\nThird Print Result\r\n");
}
printf("--------------------------------------\r\n");
for (int i = 0; i < j; i++) {
sprintf((char *)tHistory.Item, "Item %d", i);
save_history_item(&tHistory);
printf("Save History -> %s\r\n", tHistory.Item);
}
printf("--------------------------------------\r\n");
/*--------- Read prev history item ---------*/
for (int i = 0; i < j; i++) {
if (read_prev_history_item(&tHistory)) {
printf("Previous history -> %s\r\n", tHistory.Item);
} else {
printf("No Previous history\r\n");
}
}
printf("--------------------------------------\r\n");
/*--------- Read next history item ---------*/
for (int i = 0; i < j; i++) {
if (read_next_history_item(&tHistory)) {
printf("Next history -> %s\r\n", tHistory.Item);
} else {
printf("No next history\r\n");
}
}
printf("--------------------------------------\r\n");
printf("History Count -> %d\r\n", get_history_item_count());
printf("--------------------------------------\r\n");
ptHistoryPtr = get_oldest_history_item();
printf("Oldest history -> %s\r\n", ptHistoryPtr->Item);
printf("--------------------------------------\r\n");
ptHistoryPtr = get_newest_history_item();
printf("Newest history -> %s\r\n", ptHistoryPtr->Item);
printf("--------------------------------------\r\n");
} while(j++ < HISTORY_ITEM_MAX_COUNT + 1);
/* Print Result
History Item Max Count -> 5
--------------------------------------
Frist Print Result
--------------------------------------
Save History -> Item 0
Save History -> Item 1
Save History -> Item 2
Save History -> Item 3
--------------------------------------
Previous history -> Item 3
Previous history -> Item 2
Previous history -> Item 1
Previous history -> Item 0
--------------------------------------
Next history -> Item 1
Next history -> Item 2
Next history -> Item 3
No next history
--------------------------------------
History Count -> 4
--------------------------------------
Oldest history -> Item 0
--------------------------------------
Newest history -> Item 3
--------------------------------------
Second Print Result
--------------------------------------
Save History -> Item 0
Save History -> Item 1
Save History -> Item 2
Save History -> Item 3
Save History -> Item 4
--------------------------------------
Previous history -> Item 4
Previous history -> Item 3
Previous history -> Item 2
Previous history -> Item 1
Previous history -> Item 0
--------------------------------------
Next history -> Item 1
Next history -> Item 2
Next history -> Item 3
Next history -> Item 4
No next history
--------------------------------------
History Count -> 5
--------------------------------------
Oldest history -> Item 0
--------------------------------------
Newest history -> Item 4
--------------------------------------
Third Print Result
--------------------------------------
Save History -> Item 0
Save History -> Item 1
Save History -> Item 2
Save History -> Item 3
Save History -> Item 4
Save History -> Item 5
--------------------------------------
Previous history -> Item 5
Previous history -> Item 4
Previous history -> Item 3
Previous history -> Item 2
Previous history -> Item 1
No Previous history
--------------------------------------
Next history -> Item 2
Next history -> Item 3
Next history -> Item 4
Next history -> Item 5
No next history
No next history
--------------------------------------
History Count -> 5
--------------------------------------
Oldest history -> Item 1
--------------------------------------
Newest history -> Item 5
--------------------------------------
*/
}