Compare operator test suite: forward and reverse compares; edge and corner cases; literals, autos, statics, simple expressions; signed and unsigned; some special cases.
This commit is contained in:
347
test/val/compare-rev51.c
Normal file
347
test/val/compare-rev51.c
Normal file
@@ -0,0 +1,347 @@
|
||||
/* Exercise compare operator expression cases in forward and reverse forms;
|
||||
** various types: simple expressions.
|
||||
** Note: will cause some compiler warnings:
|
||||
** -- Result of comparison is constant
|
||||
** -- 'x_yyy' is defined but never used [not all defined values used]
|
||||
**
|
||||
** License: Public Domain
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied warranty.
|
||||
** In no event will the authors be held liable for any damages arising from
|
||||
** the use of this software.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define TEST_NAME "compare-rev51"
|
||||
|
||||
#include "compare-rev.h"
|
||||
|
||||
/* The indexes of compared values are kept the same across different types */
|
||||
static int stat_i[16] = {
|
||||
-32767-1, -32767, -257, -256, -255, -1, 0, 1, 255, 256, 257, 32766, 32767, 0, 0, 0
|
||||
};
|
||||
|
||||
static unsigned stat_u[16] = {
|
||||
0, 0, 0, 0, 0, -1U, 0U, 1U, 255U, 256U, 257U, 32766U, 32767U, 32768U, 65534U, 65535U
|
||||
};
|
||||
|
||||
static unsigned char stat_uc[16] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 1, 255, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/* The indexes of compared values */
|
||||
static unsigned char x_m32768 = 0;
|
||||
static unsigned char x_m32767 = 1;
|
||||
static unsigned char x_m257 = 2;
|
||||
static unsigned char x_m256 = 3;
|
||||
static unsigned char x_m255 = 4;
|
||||
static unsigned char x_m1 = 5;
|
||||
static unsigned char x_0 = 6;
|
||||
static unsigned char x_1 = 7;
|
||||
static unsigned char x_255 = 8;
|
||||
static unsigned char x_256 = 9;
|
||||
static unsigned char x_257 = 10;
|
||||
static unsigned char x_32766 = 11;
|
||||
static unsigned char x_32767 = 12;
|
||||
static unsigned char x_32768 = 13;
|
||||
static unsigned char x_65534 = 14;
|
||||
static unsigned char x_65535 = 15;
|
||||
|
||||
/* Compared values are static arrays. The actual types used in comparisons
|
||||
** are controlled here by the defines.
|
||||
*/
|
||||
#define N32768 stat_i[x_m32768]
|
||||
#define N32767 stat_i[x_m32767]
|
||||
#define N257 stat_i[x_m257]
|
||||
#define N256 stat_i[x_m256]
|
||||
#define N255 stat_i[x_m255]
|
||||
#define N1 stat_i[x_m1]
|
||||
#define ZERO stat_i[x_0]
|
||||
#define P1 stat_uc[x_1]
|
||||
#define P255 stat_uc[x_255]
|
||||
#define U255 stat_u[x_255]
|
||||
#define P256 stat_i[x_256]
|
||||
#define U256 stat_u[x_256]
|
||||
#define P257 stat_i[x_257]
|
||||
#define U257 stat_u[x_257]
|
||||
#define P32766 stat_i[x_32766]
|
||||
#define P32767 stat_i[x_32767]
|
||||
#define U32767 stat_u[x_32767]
|
||||
#define U32768 stat_u[x_32768]
|
||||
#define U65534 stat_u[x_65534]
|
||||
#define U65535 stat_u[x_65535]
|
||||
|
||||
/* signed int to static arrays compares */
|
||||
/* General form: if ((loc + 1) >= array[x_val]) */
|
||||
static void sint_expr_to_statarr_11(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
signed int loc;
|
||||
|
||||
loc = -32767-1; /* +1 = -32767 */
|
||||
marker = 0x1100; /* +8 for each macro */
|
||||
|
||||
MUST_BE_EQUAL(v, N32767);
|
||||
MUST_BE_LESS_THAN(v, N1);
|
||||
MUST_BE_LESS_THAN(v, ZERO);
|
||||
MUST_BE_LESS_THAN(v, P1);
|
||||
MUST_BE_LESS_THAN(v, P255);
|
||||
MUST_BE_LESS_THAN(v, P32767);
|
||||
}
|
||||
|
||||
static void sint_expr_to_statarr_13(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
signed int loc;
|
||||
|
||||
loc = -32767; /* +1 = -32766 */
|
||||
marker = 0x1300; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, N32767);
|
||||
MUST_BE_LESS_THAN(v, N1);
|
||||
MUST_BE_LESS_THAN(v, ZERO);
|
||||
MUST_BE_LESS_THAN(v, P1);
|
||||
MUST_BE_LESS_THAN(v, P256);
|
||||
MUST_BE_LESS_THAN(v, P32766);
|
||||
}
|
||||
|
||||
static void sint_expr_to_statarr_15(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
signed int loc;
|
||||
|
||||
loc = -258; /* +1 = 257 */
|
||||
marker = 0x1500; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, N32767);
|
||||
MUST_BE_EQUAL(v, N257);
|
||||
MUST_BE_LESS_THAN(v, N256);
|
||||
MUST_BE_LESS_THAN(v, N1);
|
||||
MUST_BE_LESS_THAN(v, ZERO);
|
||||
MUST_BE_LESS_THAN(v, P1);
|
||||
MUST_BE_LESS_THAN(v, P255);
|
||||
MUST_BE_LESS_THAN(v, P32766);
|
||||
}
|
||||
|
||||
static void sint_expr_to_statarr_17(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
signed int loc;
|
||||
|
||||
loc = -257; /* +1 = 256 */
|
||||
marker = 0x1700; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, N32767);
|
||||
MUST_BE_EQUAL(v, N256);
|
||||
MUST_BE_LESS_THAN(v, N1);
|
||||
MUST_BE_LESS_THAN(v, ZERO);
|
||||
MUST_BE_LESS_THAN(v, P1);
|
||||
MUST_BE_LESS_THAN(v, P255);
|
||||
MUST_BE_LESS_THAN(v, P32767);
|
||||
}
|
||||
|
||||
static void schar_expr_to_statarr_19(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
signed char loc;
|
||||
|
||||
loc = -3; /* +1 = -2 */
|
||||
marker = 0x1900; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, N257);
|
||||
MUST_BE_LESS_THAN(v, N1);
|
||||
MUST_BE_LESS_THAN(v, ZERO);
|
||||
MUST_BE_LESS_THAN(v, P1);
|
||||
MUST_BE_LESS_THAN(v, P255);
|
||||
MUST_BE_LESS_THAN(v, P32766);
|
||||
}
|
||||
|
||||
static void sint_expr_to_statarr_1B(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
signed int loc;
|
||||
|
||||
loc = -2; /* +1 = -1 */
|
||||
marker = 0x1B00; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, N255);
|
||||
MUST_BE_EQUAL(v, N1);
|
||||
MUST_BE_LESS_THAN(v, ZERO);
|
||||
MUST_BE_LESS_THAN(v, P1);
|
||||
MUST_BE_LESS_THAN(v, P255);
|
||||
MUST_BE_LESS_THAN(v, P32767);
|
||||
}
|
||||
|
||||
static void schar_expr_to_statarr_1D(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
signed char loc;
|
||||
|
||||
loc = -1; /* +1 = 0 */
|
||||
marker = 0x1D00; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, N255);
|
||||
MUST_BE_GREATER_THAN(v, N1);
|
||||
MUST_BE_EQUAL(v, ZERO);
|
||||
MUST_BE_LESS_THAN(v, P1);
|
||||
MUST_BE_LESS_THAN(v, P255);
|
||||
MUST_BE_LESS_THAN(v, P256);
|
||||
MUST_BE_LESS_THAN(v, U257);
|
||||
MUST_BE_LESS_THAN(v, U32768);
|
||||
}
|
||||
|
||||
static void uchar_expr_to_statarr_1F(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
unsigned char loc;
|
||||
|
||||
loc = 0; /* +1 = 1 */
|
||||
marker = 0x1F00; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, N257);
|
||||
MUST_BE_GREATER_THAN(v, N256);
|
||||
MUST_BE_GREATER_THAN(v, N1);
|
||||
MUST_BE_GREATER_THAN(v, ZERO);
|
||||
MUST_BE_EQUAL(v, P1);
|
||||
MUST_BE_LESS_THAN(v, P255);
|
||||
MUST_BE_LESS_THAN(v, P256);
|
||||
MUST_BE_LESS_THAN(v, U257);
|
||||
MUST_BE_LESS_THAN(v, P32766);
|
||||
}
|
||||
|
||||
static void uchar_expr_to_statarr_21(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
unsigned char loc;
|
||||
|
||||
loc = 1; /* +1 = 2 */
|
||||
marker = 0x2100; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, N32767);
|
||||
MUST_BE_GREATER_THAN(v, N257);
|
||||
MUST_BE_GREATER_THAN(v, N1);
|
||||
MUST_BE_GREATER_THAN(v, ZERO);
|
||||
MUST_BE_GREATER_THAN(v, P1);
|
||||
MUST_BE_LESS_THAN(v, P255);
|
||||
MUST_BE_LESS_THAN(v, U256);
|
||||
MUST_BE_LESS_THAN(v, U257);
|
||||
MUST_BE_LESS_THAN(v, U32768);
|
||||
}
|
||||
|
||||
static void uchar_expr_to_statarr_23(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
unsigned char loc;
|
||||
|
||||
loc = 254; /* +1 = 255 */
|
||||
marker = 0x2300; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, N257);
|
||||
MUST_BE_GREATER_THAN(v, N256);
|
||||
MUST_BE_GREATER_THAN(v, N255);
|
||||
MUST_BE_GREATER_THAN(v, N1);
|
||||
MUST_BE_GREATER_THAN(v, ZERO);
|
||||
MUST_BE_GREATER_THAN(v, P1);
|
||||
MUST_BE_EQUAL(v, P255);
|
||||
MUST_BE_LESS_THAN(v, P256);
|
||||
MUST_BE_LESS_THAN(v, U256);
|
||||
MUST_BE_LESS_THAN(v, U257);
|
||||
}
|
||||
|
||||
static void sint_expr_to_statarr_25(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
signed int loc;
|
||||
|
||||
loc = 255; /* +1 = 256 */
|
||||
marker = 0x2500; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, N256);
|
||||
MUST_BE_GREATER_THAN(v, N1);
|
||||
MUST_BE_GREATER_THAN(v, ZERO);
|
||||
MUST_BE_GREATER_THAN(v, P1);
|
||||
MUST_BE_GREATER_THAN(v, U255);
|
||||
MUST_BE_EQUAL(v, P256);
|
||||
MUST_BE_LESS_THAN(v, P257);
|
||||
MUST_BE_LESS_THAN(v, P32766);
|
||||
}
|
||||
|
||||
static void uint_expr_to_statarr_27(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
unsigned int loc;
|
||||
|
||||
loc = 256; /* +1 = 257 */
|
||||
marker = 0x2700; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, ZERO);
|
||||
MUST_BE_GREATER_THAN(v, P1);
|
||||
MUST_BE_GREATER_THAN(v, P255);
|
||||
MUST_BE_GREATER_THAN(v, P256);
|
||||
MUST_BE_EQUAL(v, U257);
|
||||
MUST_BE_LESS_THAN(v, P32767);
|
||||
MUST_BE_LESS_THAN(v, U32768);
|
||||
}
|
||||
|
||||
static void uint_expr_to_statarr_29(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
unsigned int loc;
|
||||
|
||||
loc = 32766; /* +1 = 32767 */
|
||||
marker = 0x2900; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, ZERO);
|
||||
MUST_BE_GREATER_THAN(v, P1);
|
||||
MUST_BE_GREATER_THAN(v, P255);
|
||||
MUST_BE_GREATER_THAN(v, U255);
|
||||
MUST_BE_GREATER_THAN(v, P257);
|
||||
MUST_BE_GREATER_THAN(v, P32766);
|
||||
MUST_BE_EQUAL(v, P32767);
|
||||
MUST_BE_LESS_THAN(v, U32768);
|
||||
MUST_BE_LESS_THAN(v, U65535);
|
||||
}
|
||||
|
||||
static void uint_expr_to_statarr_2B(void)
|
||||
{
|
||||
#define v (loc + 1)
|
||||
unsigned int loc;
|
||||
|
||||
loc = 32767; /* +1 = 32768 */
|
||||
marker = 0x2B00; /* +8 for each macro */
|
||||
|
||||
MUST_BE_GREATER_THAN(v, ZERO);
|
||||
MUST_BE_GREATER_THAN(v, P1);
|
||||
MUST_BE_GREATER_THAN(v, P255);
|
||||
MUST_BE_GREATER_THAN(v, U256);
|
||||
MUST_BE_GREATER_THAN(v, P32767);
|
||||
MUST_BE_EQUAL(v, U32768);
|
||||
MUST_BE_LESS_THAN(v, U65534);
|
||||
MUST_BE_LESS_THAN(v, U65535);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
marker = 0x01;
|
||||
|
||||
sint_expr_to_statarr_11();
|
||||
sint_expr_to_statarr_13();
|
||||
sint_expr_to_statarr_15();
|
||||
sint_expr_to_statarr_17();
|
||||
schar_expr_to_statarr_19();
|
||||
sint_expr_to_statarr_1B();
|
||||
schar_expr_to_statarr_1D();
|
||||
uchar_expr_to_statarr_1F();
|
||||
uchar_expr_to_statarr_21();
|
||||
uchar_expr_to_statarr_23();
|
||||
sint_expr_to_statarr_25();
|
||||
uint_expr_to_statarr_27();
|
||||
uint_expr_to_statarr_29();
|
||||
uint_expr_to_statarr_2B();
|
||||
|
||||
printf(TEST_NAME " failures: %d\n", failures);
|
||||
|
||||
return failures ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user