Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
test_stdio_1.c
Package: mysql-3.23.35.tar.gz [view]
Upload User: tsgydb
Upload Date: 2007-04-14
Package Size: 10674k
Code Size: 2k
Category:
MySQL
Development Platform:
Visual C++
- #include <pthread.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- char * base_name = "test_stdio_1.c";
- char * dir_name = SRCDIR;
- char * fullname;
- #define OK 0
- #define NOTOK -1
- /* Test fopen()/ftell()/getc() */
- int test_1(void)
- {
- struct stat statbuf;
- FILE * fp;
- int i;
- if (stat(fullname, &statbuf) < OK) {
- printf("ERROR: Couldn't stat %sn", fullname);
- return(NOTOK);
- }
- if ((fp = fopen(fullname, "r")) == NULL) {
- printf("ERROR: Couldn't open %sn", fullname);
- return(NOTOK);
- }
- /* Get the entire file */
- while ((i = getc(fp)) != EOF);
- if (ftell(fp) != statbuf.st_size) {
- printf("ERROR: ftell() and stat() don't agree.");
- return(NOTOK);
- }
- if (fclose(fp) < OK) {
- printf("ERROR: fclose() failed.");
- return(NOTOK);
- }
- return(OK);
- }
- /* Test fopen()/fclose() */
- int test_2(void)
- {
- FILE *fp1, *fp2;
- if ((fp1 = fopen(fullname, "r")) == NULL) {
- printf("ERROR: Couldn't fopen %sn", fullname);
- return(NOTOK);
- }
- if (fclose(fp1) < OK) {
- printf("ERROR: fclose() failed.");
- return(NOTOK);
- }
- if ((fp2 = fopen(fullname, "r")) == NULL) {
- printf("ERROR: Couldn't fopen %sn", fullname);
- return(NOTOK);
- }
- if (fclose(fp2) < OK) {
- printf("ERROR: fclose() failed.");
- return(NOTOK);
- }
- if (fp1 != fp2) {
- printf("ERROR: FILE table leak.n");
- return(NOTOK);
- }
- return(OK);
- }
- /* Test sscanf()/sprintf() */
- int test_3(void)
- {
- char * str = "10 4.53";
- char buf[64];
- double d;
- int i;
- if (sscanf(str, "%d %lf", &i, &d) != 2) {
- printf("ERROR: sscanf didn't parse input string correctlyn");
- return(NOTOK);
- }
- /* Should have a check */
- sprintf(buf, "%d %2.2lf", i, d);
- if (strcmp(buf, str)) {
- printf("ERROR: sscanf()/sprintf() didn't parse unparse correctlyn");
- return(NOTOK);
- }
- return(OK);
- }
- main()
- {
- printf("test_stdio_1 STARTn");
- if (fullname = malloc (strlen (dir_name) + strlen (base_name) + 2)) {
- sprintf (fullname, "%s/%s", dir_name, base_name);
- } else {
- perror ("malloc");
- exit(1);
- }
- if (test_1() || test_2() || test_3()) {
- printf("test_stdio_1 FAILEDn");
- exit(1);
- }
- printf("test_stdio_1 PASSEDn");
- exit(0);
- }