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
|
/* frecnt-2.c -- Test for decoder in libsframe.
Copyright (C) 2022-2026 Free Software Foundation, 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 3 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, see <http://www.gnu.org/licenses/>. */
#include "sframe-test.h"
/*
* SFrame info from the following source (2 fde 8 fres):
* static int cnt;
* int foo() { return ++cnt; }
* int main() { return foo(); }
*/
#define DATA "DATA2"
int
main (void)
{
sframe_decoder_ctx *dctx = NULL;
uint32_t nfres, fsize;
int32_t fstart;
unsigned char finfo;
unsigned int i;
int err = 0;
FILE *fp;
struct stat st;
char *sf_buf;
size_t sf_size;
uint8_t rep_block_size;
fp = fopen (DATA, "r");
if (fp == NULL)
goto setup_fail;
if (fstat (fileno (fp), &st) < 0)
{
perror ("fstat");
fclose (fp);
goto setup_fail;
}
sf_buf = malloc (st.st_size);
if (sf_buf == NULL)
{
perror ("malloc");
goto setup_fail;
}
/* Execute tests. */
sf_size = fread (sf_buf, 1, st.st_size, fp);
fclose (fp);
TEST (sf_size != 0, "frecnt-2: Read data");
dctx = sframe_decode (sf_buf, sf_size, &err);
TEST (dctx != NULL, "frecnt-2: Decode setup");
unsigned int fde_cnt = sframe_decoder_get_num_fidx (dctx);
TEST (fde_cnt == 2, "frecnt-2: Decode FDE count");
for (i = 0; i < fde_cnt; ++i)
{
err = sframe_decoder_get_funcdesc_v2 (dctx, i, &nfres, &fsize, &fstart,
&finfo, &rep_block_size);
TEST (err == 0, "frecnt-2: Decode get FDE%d", i);
TEST (nfres == 4, "frecnt-2: Decode num FREs for FDE%d", i);
}
free (sf_buf);
sf_buf = NULL;
sframe_decoder_free (&dctx);
return 0;
setup_fail:
sframe_decoder_free (&dctx);
fail ("frecnt-2: Test setup");
return 1;
}
|