File: tst_broken_files.c

package info (click to toggle)
netcdf-parallel 1%3A4.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 113,164 kB
  • sloc: ansic: 267,893; sh: 12,869; cpp: 5,822; yacc: 2,613; makefile: 1,813; lex: 1,216; xml: 173; awk: 2
file content (48 lines) | stat: -rw-r--r-- 1,374 bytes parent folder | download | duplicates (4)
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
/* This is part of the netCDF package.
   Copyright 2018 University Corporation for Atmospheric Research/Unidata
   See COPYRIGHT file for conditions of use.
    
   Test that netCDF provides proper error messages if broken Files are supplied.
*/

#include <config.h>
#include <stdio.h>
#include <nc_tests.h>
#include "err_macros.h"
#include "netcdf.h"
#include "netcdf_mem.h"

#include <string.h>

#define FILE_NAME "tst_broken_files.nc"
#define TRUNCATED_FILE_CONTENT "\x89HDF\r\n\x1a\n"

int
main() {
    printf("\n*** Testing NetCDF-4 with truncated (broken) sample file.\n");
    {
        printf("*** testing via file on file-system ...\n");
#if defined _WIN32 || defined __MINGW32__
        FILE *fp = fopen(FILE_NAME, "wb");
#else
	        FILE *fp = fopen(FILE_NAME, "w");
#endif
        if(!fp) ERR;
        if(fwrite(TRUNCATED_FILE_CONTENT, sizeof(char), sizeof(TRUNCATED_FILE_CONTENT), fp) != sizeof(TRUNCATED_FILE_CONTENT)) ERR;
        fclose(fp);


        int  ncid, stat;
        stat = nc_open(FILE_NAME, 0, &ncid);
        if (stat != NC_EHDFERR && stat != NC_ENOFILTER && stat != NC_ENOTNC) ERR;

    }

    {
        printf("*** testing via in-memory access ...\n");
        int  ncid;
        if (nc_open_mem(FILE_NAME, 0, sizeof(TRUNCATED_FILE_CONTENT), TRUNCATED_FILE_CONTENT, &ncid) != NC_EHDFERR) ERR;
    }
    SUMMARIZE_ERR;
    FINAL_RESULTS;
}