unittest.c

来自「Datamatrix二维码库和测试程序,运行于linux,仔细研究可以很容易转化」· C语言 代码 · 共 106 行

C
106
字号
/*libdmtx - Data Matrix Encoding/Decoding LibraryCopyright (c) 2007 Mike LaughtonThis library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USAContact: mike@dragonflylogic.com*//* $Id: unittest.c 426 2008-09-18 18:22:38Z mblaughton $ */#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#include <stdlib.h>#include <stdio.h>#include <string.h>#include <dmtx.h>#include "../../util/common/dmtxutil.h"char *programName;static void timeAddTest(void);static void timePrint(DmtxTime t);intmain(int argc, char *argv[]){   programName = argv[0];   timeAddTest();   exit(0);}/** * * */static voidtimePrint(DmtxTime t){#ifdef _MSC_VER   fprintf(stdout, "t.sec: %llu\n", t.sec);#else   fprintf(stdout, "t.sec: %lu\n", t.sec);#endif   fprintf(stdout, "t.usec: %lu\n", t.usec);}/** * * */static voidtimeAddTest(void){   DmtxTime t0, t1;   t0 = dmtxTimeNow();   t0.usec = 999000;   t1 = dmtxTimeAdd(t0, 0);   if(memcmp(&t0, &t1, sizeof(DmtxTime)) != 0)      FatalError(1, "timeAddTest\n");   t1 = dmtxTimeAdd(t0, 1);   if(memcmp(&t0, &t1, sizeof(DmtxTime)) == 0)      FatalError(2, "timeAddTest\n");   t1 = dmtxTimeAdd(t0, 1);   if(t1.sec != t0.sec + 1 || t1.usec != 0) {      timePrint(t0);      timePrint(t1);      FatalError(3, "timeAddTest\n");   }   t1 = dmtxTimeAdd(t0, 1001);   if(t1.sec != t0.sec + 2 || t1.usec != 0) {      timePrint(t0);      timePrint(t1);      FatalError(4, "timeAddTest\n");   }   t1 = dmtxTimeAdd(t0, 2002);   if(t1.sec != t0.sec + 3 || t1.usec != 1000) {      timePrint(t0);      timePrint(t1);      FatalError(5, "timeAddTest\n");   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?