Skip to content

Commit

Permalink
Add a reasonably useless test of file reading and writing.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianwalenz committed Nov 7, 2018
1 parent a71902b commit 618f916
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,6 @@ SUBMAKEFILES := stores/dumpBlob.mk \
fastq-utilities/fastqSimulate-sort.mk

ifeq ($(BUILDTESTS), 1)
SUBMAKEFILES += utility/bitsTest.mk
SUBMAKEFILES += utility/bitsTest.mk \
utility/filesTest.mk
endif
85 changes: 85 additions & 0 deletions src/utility/filesTest.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

/******************************************************************************
*
* This file is part of canu, a software program that assembles whole-genome
* sequencing reads into contigs.
*
* This software is based on:
* 'Celera Assembler' (http://wgs-assembler.sourceforge.net)
* the 'kmer package' (http://kmer.sourceforge.net)
* both originally distributed by Applera Corporation under the GNU General
* Public License, version 2.
*
* Canu branched from Celera Assembler at its revision 4587.
* Canu branched from the kmer project at its revision 1994.
*
* Modifications by:
*
* File 'README.licenses' in the root directory of this distribution contains
* full conditions and disclaimers for each license.
*/

// g++6 -o filesTest -I.. -I. filesTest.C files.C

#include "files.H"

typedef uint8 TYPE;


int32
main(int32 argc, char **argv) {
uint64 nObj = (uint64)16 * 1024 * 1024;
TYPE *array = new TYPE [nObj];
TYPE value = 0;


if (1) {
fprintf(stderr, "Initializing.\n");

for (uint64 ii=0; ii<nObj; ii++)
array[ii] = ii;

fprintf(stderr, "Writing.\n");

FILE *OUT = AS_UTL_openOutputFile("./filesTest.dat");

writeToFile(array, "array", nObj, OUT);

AS_UTL_closeFile(OUT);
}


if (1) {
fprintf(stderr, "Reading - as one block.\n");

FILE *IN = AS_UTL_openInputFile("./filesTest.dat");
loadFromFile(array, "array", nObj, IN);
AS_UTL_closeFile(IN);

for (uint64 ii=0; ii<nObj; ii++)
assert(array[ii] == (TYPE)ii);
}


if (1) {
fprintf(stderr, "Reading.\n");

FILE *IN = AS_UTL_openInputFile("./filesTest.dat");

for (uint64 ii=0; ii<nObj; ii++) {
loadFromFile(value, "value", IN);

assert(value == (TYPE)ii);
}

fprintf(stderr, "Reading - one after eof.\n");
loadFromFile(value, "value", IN, false);
loadFromFile(value, "value", IN, true);

AS_UTL_closeFile(IN);
}


exit(0);
}

20 changes: 20 additions & 0 deletions src/utility/filesTest.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# If 'make' isn't run from the root directory, we need to set these to
# point to the upper level build directory.
ifeq "$(strip ${BUILD_DIR})" ""
BUILD_DIR := ../$(OSTYPE)-$(MACHINETYPE)/obj
endif
ifeq "$(strip ${TARGET_DIR})" ""
TARGET_DIR := ../$(OSTYPE)-$(MACHINETYPE)
endif

TARGET := filesTest
SOURCES := filesTest.C

SRC_INCDIRS := .. ../utility

TGT_LDFLAGS := -L${TARGET_DIR}/lib
TGT_LDLIBS := -lcanu
TGT_PREREQS := libcanu.a

SUBMAKEFILES :=

0 comments on commit 618f916

Please sign in to comment.