©2004 by Marc J. Rochkind. All rights reserved. Portions marked "Open Source" may be copied under license.

 

Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ux/uxtestfile.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2003 by Marc J. Rochkind. All rights reserved.
00003     May be copied only for purposes and under conditions described
00004     on the Web page www.basepath.com/aup/copyright.htm.
00005 
00006     The Example Files are provided "as is," without any warranty;
00007     without even the implied warranty of merchantability or fitness
00008     for a particular purpose. The author and his publisher are not
00009     responsible for any damages, direct or incidental, resulting
00010     from the use or non-use of these Example Files.
00011 
00012     The Example Files may contain defects, and some contain deliberate
00013     coding mistakes that were included for educational reasons.
00014     You are responsible for determining if and how the Example Files
00015     are to be used.
00016 
00017 */
00018 #include "ux.hpp"
00019 
00020 using namespace Ux;
00021 
00022 static void terminal_test(void)
00023 {
00024     Terminal trm(STDIN_FILENO);
00025     char buf[1000];
00026 
00027     cout << endl << "terminal test" << endl;
00028     cout << "isatty: " << trm.isatty() << endl;
00029     trm.ttyname(buf, sizeof(buf));
00030     cout << "ttyname: " << buf << endl;
00031     Termios tios;
00032     trm.tcgetattr(tios);
00033     cout << "i speed: " << tios.cfgetispeed() << endl;
00034     cout << "o speed: " << tios.cfgetospeed() << endl;
00035 }
00036 
00037 static void posixshm_test(void)
00038 {
00039     const char *shm_path = "/posix_shm";
00040     PosixShm m;
00041 
00042     cout << endl << "POSIX shared memory test" << endl;
00043     
00044     try {
00045         m.unlink(shm_path);
00046     }
00047     catch (Error& e) {
00048         if (e == ENOSYS) {
00049             cout << "*** POSIX shared memory not supported." << endl;
00050             return;
00051         }
00052         // otherwise ignore the error
00053     }
00054     cout << "Getting ready to open..." << endl;
00055     EC_CATCH( m.open(shm_path, O_RDWR | O_CREAT) )
00056     cout << "... opened" << endl;
00057     m.truncate(10000);
00058     char *p = (char *)m.mmap(10000);
00059     strcpy(p, "This is data for POSIX shared memory.");
00060     m.munmap(p, 10000);
00061     p = (char *)m.mmap(10000);
00062     cout << "Got: \"" << p << "\"" << endl; 
00063     m.unlink(shm_path);
00064 }
00065 
00066 static void posixmsg_test(void)
00067 {
00068     const char *msg_path = "/posix_mq2";
00069     PosixMsg m;
00070     const char *s = "A POSIX message.";
00071     char buf[2000];
00072     ssize_t n;
00073     struct mq_attr attr;
00074 
00075     cout << endl << "POSIX message test" << endl;
00076     
00077     try {
00078         m.unlink(msg_path);
00079     }
00080     catch (Error& e) {
00081         if (e == ENOSYS) {
00082             cout << "*** POSIX messages not supported." << endl;
00083             return;
00084         }
00085         // otherwise ignore the error
00086     }
00087     cout << "Getting ready to open..." << endl;
00088     EC_CATCH( m.open(msg_path, O_RDWR | O_CREAT) )
00089     cout << "... opened" << endl;
00090     EC_CATCH( m.getattr(&attr) )
00091     cout << "maxmsg: " << attr.mq_maxmsg << "; msgsize: " << attr.mq_msgsize << endl;
00092     EC_CATCH( m.send(s, strlen(s)) )
00093     EC_CATCH( n = m.receive(buf, sizeof(buf) - 1) )
00094     buf[n] = '\0';
00095     cout << "Got: \"" << buf << "\"" << endl;
00096     EC_CATCH( m.close() )
00097     EC_CATCH( m.unlink(msg_path) )
00098     cout << "POSIX message text finished" << endl;
00099 }
00100 
00101 static void handler(int signum)
00102 {
00103     cout << "Got signal " << signum << endl;
00104 }
00105 
00106 static void sysvsem_test(void)
00107 {
00108     const char *sem_path = "sysv_sem";
00109     union semun arg;
00110     struct sembuf sbuf;
00111 
00112     cout << endl << "SysV semaphore test" << endl;
00113     File f(sem_path);
00114     EC_CATCH( f.open(O_WRONLY | O_CREAT) )
00115     f.close();
00116     key_t k = SysVIPC::ftok(sem_path, 1);
00117     SysVSem s;
00118     EC_CATCH( s.get(k, 1) )
00119     arg.val = 0;
00120     EC_CATCH( s.ctl(0, SETVAL, arg) )
00121     sbuf.sem_num = 0;
00122     sbuf.sem_op = 1;
00123     sbuf.sem_flg = 0;
00124     EC_CATCH( s.op(&sbuf, 1) )
00125     struct sigaction act;
00126     memset(&act, 0, sizeof(act));
00127     act.sa_handler = handler;
00128     Process::sigaction(SIGALRM, &act);
00129     Timer::alarm(2);
00130     sbuf.sem_op = 0;
00131     try {
00132         s.op(&sbuf, 1);
00133     }
00134     catch (const Error& e) {
00135         if (e == EINTR)
00136             cout << "op interrupted, as expected" << endl;
00137         else
00138             throw;
00139     }
00140     EC_CATCH( s.ctl(0, IPC_RMID, arg) )
00141     cout << "SysV semaphore test finished" << endl;
00142 }
00143 
00144 static void posixsem_test(void)
00145 {
00146     const char *sem_path = "/posix_sem";
00147 
00148     cout << endl << "Posix semaphore test" << endl;
00149     PosixSem s;
00150     try {
00151         s.open(sem_path, O_RDWR | O_CREAT);
00152     }
00153     catch (Error& e) {
00154         if (e == ENOSYS) {
00155             cout << "*** POSIX semaphores not supported." << endl;
00156             return;
00157         }
00158         else
00159             EC_EXIT(e)
00160     }
00161     struct sigaction act;
00162     memset(&act, 0, sizeof(act));
00163     act.sa_handler = handler;
00164     Process::sigaction(SIGALRM, &act);
00165     Timer::alarm(2);
00166     try {
00167         s.wait();
00168     }
00169     catch (const Error& e) {
00170         if (e == EINTR)
00171             cout << "wait interrupted, as expected" << endl;
00172         else
00173             throw;
00174     }
00175     EC_CATCH( s.post() )
00176     EC_CATCH( s.wait() ) // should not block
00177     EC_CATCH( s.close() )
00178     EC_CATCH( s.unlink(sem_path) )
00179     cout << "POSIX semaphore test finished" << endl;
00180 }
00181 
00182 static void sysvshm_test(void)
00183 {
00184     const char *shm_path = "sysv_shm";
00185 
00186     cout << endl << "SysV shared memory test" << endl;
00187     File f(shm_path);
00188     EC_CATCH( f.open(O_WRONLY | O_CREAT) )
00189     f.close();
00190     key_t k = SysVIPC::ftok(shm_path, 1);
00191     SysVShm m;
00192     EC_CATCH( m.get(k, 1000) )
00193     char *p = (char *)m.at();
00194     strcpy(p, "Some data for the shared memory segment.");
00195     m.dt(p);
00196     p = (char *)m.at();
00197     cout << "Got: \"" << p << "\"" << endl; 
00198     m.ctl(IPC_RMID);
00199 }
00200 
00201 static void sysvmsg_test(void)
00202 {
00203     const char *msgq_path = "sysv_msgq";
00204     struct {
00205         long mtype;
00206         char mtext[1000];
00207     } msg = { 1 }, msg2;
00208 
00209     cout << endl << "SysV message test" << endl;
00210     File f(msgq_path);
00211     EC_CATCH( f.open(O_WRONLY | O_CREAT) )
00212     f.close();
00213     key_t k = SysVIPC::ftok(msgq_path, 1);
00214     cout << "key: " << k << endl;
00215 
00216     SysVMsg q;
00217     EC_CATCH( q.get(k) )
00218     strcpy(msg.mtext, "SysV message");
00219     EC_CATCH( q.snd(&msg, strlen(msg.mtext)) )
00220     ssize_t n;
00221     EC_CATCH( n = q.rcv(&msg2, sizeof(msg2.mtext) - 1) )
00222     msg2.mtext[n] = '\0';
00223     cout << "Got: \"" << msg2.mtext << "\"" << endl;
00224     q.ctl(IPC_RMID);
00225 }
00226 
00227 static void socket_test_unix(void)
00228 {
00229     Socket s("MySocket");
00230     Process p;
00231     File pfd[2];
00232     
00233     try {
00234         s.unlink();
00235     }
00236     catch (...) {
00237     };
00238     SockAddrUn sa(s);
00239     File::pipe(pfd);
00240     if ((p = Process::fork()) == 0) {
00241         char c;
00242 
00243         pfd[1].close();
00244         pfd[0].read(&c, 1);
00245         pfd[0].close();
00246         EC_CATCH( s.socket() )
00247         EC_CATCH( s.connect(sa) )
00248         cout << "Child connected!" << endl;
00249         EC_CATCH( s.write("Hello", 6) )
00250         s.close();
00251         Process::exit();
00252     }
00253     else {
00254         Socket client;
00255         char msg[100];
00256     
00257         EC_CATCH( s.socket() )
00258         EC_CATCH( s.bind(sa) )
00259         EC_CATCH( s.listen() )
00260         pfd[0].close();
00261         pfd[1].close();
00262         EC_CATCH( client = s.accept() )
00263         cout << "Parent accepted!" << endl;
00264         EC_CATCH( client.read(msg, sizeof(msg)) )
00265         client.close();
00266         s.close();
00267         cout << "Parent got message: " << msg << endl;
00268     }
00269 }
00270 
00271 static void socket_test_inet(void)
00272 {
00273     Socket s;
00274     Process p;
00275     File pfd[2];
00276 
00277 cout << 1 << endl;
00278 #if defined(SOLARIS)
00279     SockAddrIn sa(1001, "192.168.0.10"); // Sol
00280 #elif defined(LINUX)
00281     SockAddrIn sa(1001, "192.168.0.19"); // Suse
00282 #endif
00283 cout << 2 << endl;
00284     File::pipe(pfd);
00285     if ((p = Process::fork()) == 0) {
00286         char c;
00287 
00288         pfd[1].close();
00289         pfd[0].read(&c, 1);
00290         pfd[0].close();
00291         EC_CATCH( s.socket(AF_INET) )
00292         EC_CATCH( s.connect(sa) )
00293         cout << "Child connected!" << endl;
00294         EC_CATCH( s.write("Hello", 6) )
00295         s.close();
00296         Process::exit();
00297     }
00298     else {
00299         Socket client;
00300         char msg[100];
00301     
00302         EC_CATCH( s.socket(AF_INET) )
00303         EC_CATCH( s.bind(sa) )
00304         EC_CATCH( s.listen() )
00305         pfd[0].close();
00306         pfd[1].close();
00307         EC_CATCH( client = s.accept() )
00308         cout << "Parent accepted!" << endl;
00309         EC_CATCH( client.read(msg, sizeof(msg)) )
00310         client.close();
00311         s.close();
00312         cout << "Parent got message: " << msg << endl;
00313     }
00314 }
00315 
00316 static void sockip_test(void)
00317 {
00318     char buf[100];
00319 
00320     SockIPv4 si4("64.81.102.0");
00321     cout << "As IPv4: " << si4.get_ipv4() << endl;
00322     cout << "As dotted: " << si4.get_string(buf, sizeof(buf)) << endl;
00323     SockIPv6 si6("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210");
00324     cout << "As IPv6:";
00325     for (int i = 0; i < 16; i++)
00326         cout << " " << (int)si6.get_ipv6()[i];
00327     cout << endl;
00328     cout << "As dotted: " << si6.get_string(buf, sizeof(buf)) << endl;
00329 }
00330 
00331 static void browser_test(void)
00332 {
00333     SockAddr sa;
00334     Socket s;
00335     char buf[512];
00336     const char *request = "GET / HTTP/1.0\n\n";
00337 
00338     sa.set_server("www.basepath.com");
00339     s.socket(AF_INET, SOCK_STREAM, sa.get_protocol());
00340     s.connect(sa);
00341     s.write(request, strlen(request));
00342     ssize_t n = s.read(buf, sizeof(buf) - 1);
00343     buf[n] = '\0';
00344     cout << endl << endl << buf << endl<< endl;
00345 }
00346 
00347 static void new_time_test(void)
00348 {
00349     TimeParts tm;
00350     TimeString ts;
00351     TimeSec tnow(now);
00352     TimeString snow(tnow);
00353     TimeString snow2((time_t)TimeSec());
00354     TimeString snow3((time_t)TimeSec(now));
00355     TimeMsec tnowmsec(now), tepochmsec(epoch);
00356     TimeNsec tnownsec(now), tepochnsec(epoch);
00357 
00358     cout << endl << "new_time_test" << endl;
00359     cout << "now: " << snow;
00360     cout << "now: " << snow3;
00361     cout << "epoch (TimeString): " << snow2;
00362     cout << "epoch (TimeParts): " << tm << endl;;
00363     tm.set_fmt("12-June-2003", "%d-%b-%Y");
00364     cout << "My Birthday (wrong wday): " << tm << endl;
00365     cout << "My Birthday (right wday): " << TimeParts(tm.get_secs()) << endl;
00366     char sbuf[100];
00367     tm.get_fmt(sbuf, sizeof(sbuf), "%x %X");
00368     cout << "My Birthday (right wday, strftime): " << sbuf << endl;
00369     try {
00370         tm.set("12-June-2003");
00371         cout << "My Birthday: " << tm << endl;
00372     }
00373     catch (const Error& e) {
00374         cout << "set(const char *) failed, as expected: " << e << endl;
00375     }
00376     cout << "ts as constructed: " << ts << endl;
00377     ts.set(INT_MIN);
00378     cout << "bgn of time: " << ts;
00379     ts.set(INT_MAX);
00380     cout << "end of time: " << ts;
00381     cout << "now in msecs: " << tnowmsec.get_string(sbuf, sizeof(sbuf)) << endl;
00382     cout << "now in msecs: " << tnowmsec << endl;
00383     cout << "epoch in msecs: " << tepochmsec << endl;
00384     cout << "now in nsecs: " << tnownsec.get_string(sbuf, sizeof(sbuf)) << endl;
00385     cout << "now in nsecs: " << tnownsec << endl;
00386     cout << "epoch in nsecs: " << tepochnsec << endl;
00387 
00388 #if 0
00389     cout << "Epoch: " << tm << endl;
00390     cout << "Now: " << Timestr().ctime();
00391     tm.tm_year = 98;
00392     cout << "1998: " << tm << endl;
00393 #endif
00394 }
00395 
00396 static void time_test(void)
00397 {
00398     Timetm tm;
00399     Timestr ts;
00400 
00401     cout << "Epoch: " << tm << endl;
00402     cout << "Now: " << Timestr().ctime();
00403     tm.tm_year = 98;
00404     cout << "1998: " << tm << endl;
00405     cout << "ts as constructed: " << ts << endl;
00406     cout << "bgn of time: " << Timestr().ctime(INT_MIN);
00407     cout << "end of time: " << Timestr().ctime(INT_MAX);
00408     tm.strptime("12-June-2003", "%d-%b-%Y");
00409     cout << "My Birthday (wrong wday): " << tm << endl;
00410     cout << "My Birthday (right wday): " << Timetm(tm.mktime()) << endl;
00411     try {
00412         tm.getdate("12-June-2003");
00413         cout << "My Birthday: " << tm << endl;
00414     }
00415     catch (const Error& e) {
00416         cout << "getdate failed, as expected: " << e << endl;
00417     }
00418     char sbuf[100];
00419     tm.strftime(sbuf, sizeof(sbuf), "%x %X");
00420     cout << "My Birthday (right wday, strftime): " << sbuf << endl;
00421 }
00422 
00423 static void sigset_test(void)
00424 {
00425     Sigset set;
00426 
00427     set.add(SIGINT);
00428     if (!set.ismember(SIGINT))
00429         cout << "add error" << endl;
00430     set.del(SIGINT);
00431     if (set.ismember(SIGINT))
00432         cout << "del error" << endl;
00433     set.fill();
00434     if (!set.ismember(SIGINT) || !set.ismember(SIGUSR1))
00435         cout << "fill error" << endl;
00436     cout << "+++ End of sigset_test +++" << endl;
00437 }
00438 
00439 static void at_exit_fcn(void)
00440 {
00441     cout << endl << "atexit fcn called" << endl;
00442 }
00443 
00444 static void dirstream_test(void)
00445 {
00446     DirStream d;
00447     int i;
00448     long loc;
00449 
00450     d.open_alloc("/aup");
00451     for (i = 0; d.read(); i++) {
00452         cout << "dir entry " << i << ": " << d.get_name() << endl;
00453         if (i == 3)
00454             loc = d.tell();
00455     }
00456     d.seek(loc);
00457     if (d.read())
00458         cout << "dir entry 4 again: " << d.get_name() << endl;
00459     d.rewind();
00460     if (d.read())
00461         cout << "dir entry 1 again: " << d.get_name() << endl;
00462     d.close();
00463     cout << "+++ End of dirstream_test +++" << endl;
00464 }
00465 
00466 static void process_test(void)
00467 {
00468     Process p;
00469     ExitStatus status;
00470     
00471     Process::atexit(at_exit_fcn);
00472     if ((p = Process::fork()) == 0) {
00473         try {
00474             Process::execlp("echo", "echo", "arg_one", "arg_two", "arg_three", NULL);
00475         }
00476         catch (const Error& e) {
00477             EC__EXIT(e)
00478         }
00479     }
00480     p.waitpid(&status);
00481     cout << "Process " << p << " exit status: " << status << endl;
00482     if ((p = Process::fork()) == 0) {
00483         char *av[] = {"sh", "-c", "set", NULL };
00484         char *ev[] = {"SOMETHING=DOGCOW", NULL};
00485 
00486         try {
00487             Process::execvpe("sh", av, ev);
00488         }
00489         catch (const Error& e) {
00490             EC__EXIT(e)
00491         }
00492     }
00493     p.waitpid(&status);
00494     cout << "Process " << p << " exit status: " << status << endl;
00495     if ((p = Process::fork()) == 0) {
00496         try {
00497             Process::pause();
00498         }
00499         catch (const Error& e) {
00500             EC__EXIT(e)
00501         }
00502     }
00503     Clock::sleep(1);
00504     Clock::usleep(123456);
00505     p.kill(SIGFPE);
00506     p.waitpid(&status);
00507     cout << "Process " << p << " exit status: " << status << endl;
00508 
00509     Dir dcwd;
00510     dcwd.alloc();
00511     Process::getcwd(dcwd);
00512     cout << dcwd << endl;
00513     
00514     Dir d(".");
00515     d.open(O_RDONLY);
00516     Process::chdir("/tmp");
00517     Process::getcwd(dcwd);
00518     cout << dcwd << endl;
00519     Process::chdir(d.get_fd());
00520     d.close();
00521     Process::getcwd(dcwd);
00522     cout << dcwd << endl;
00523     dcwd.free();
00524 
00525     struct rlimit rl;
00526     Process::getrlimit(RLIMIT_DATA, &rl);
00527     cout << "RLIMIT_DATA: cur = " << rl.rlim_cur << "; max = " << rl.rlim_max << endl;
00528     struct rusage usage;
00529     Process::getrusage(RUSAGE_SELF, &usage);
00530     cout << "Time: " << usage.ru_utime << endl;
00531     Process::nice(10);
00532     rl.rlim_cur = 0;
00533     Process::setrlimit(RLIMIT_CORE, &rl);
00534     try {
00535         Process::chroot("/tmp");
00536     }
00537     catch (const Error& e) {
00538         cout << e << endl;
00539     }
00540     cout << "+++ End of process_test +++" << endl;
00541 }
00542 
00543 static void process_env_test(void)
00544 {
00545     try {
00546         cout << "HOME = " << getenv("HOME") << endl;
00547         Process::putenv("NEWVAR=newvalue");
00548         cout << "NEWVAR = " << getenv("NEWVAR") << endl;
00549         Process::unsetenv("NEWVAR");
00550         cout << "NEWVAR = " << getenv("NEWVAR") << endl;
00551         Process::setenv("NEWVAR", "another value", true);
00552         cout << "NEWVAR = " << getenv("NEWVAR") << endl;
00553     }
00554     catch (const exception& e) {
00555         cout << e.what() << endl;
00556     }
00557 /*
00558     catch (const Error& e) {
00559         cout << "process_env_test caught an error: " << e << endl;
00560     }
00561 */
00562     cout << "+++ End of process_env_test +++" << endl;
00563 }
00564 
00565 static void pipe_test(void)
00566 {
00567     File pf[2];
00568     char buf[100];
00569     
00570     File::pipe(pf);
00571     pf[1].write("Something", 10);
00572     pf[0].read(buf, sizeof(buf));
00573     File(STDOUT_FILENO).write(buf, strlen(buf));
00574     File(STDOUT_FILENO).write("\n", 1);
00575     cout << "+++ End of pipe_test +++" << endl;
00576 }
00577 
00578 #define PATH "/aup/aup2ex.tar"
00579 #define FREQ 8000
00580 
00581 static void aio_test(void)
00582 {
00583     File f(PATH);
00584     int count = 0, e;
00585     char buf1[512], buf2[512];
00586     Aio cb;
00587     const struct aiocb *list[1] = { &cb };
00588 
00589     cb.aio_fildes = STDIN_FILENO;
00590     cb.aio_buf = buf2;
00591     cb.aio_nbytes = sizeof(buf2);
00592     cb.aio_sigevent.sigev_notify = SIGEV_NONE;
00593     f.open(O_RDONLY);
00594     timestart();
00595     while (f.read(buf1, sizeof(buf1)) > 0) {
00596         if (count % FREQ == 0) {
00597             if (count > 1) {
00598                 Aio::suspend(list, 1);
00599                 if ((e = cb.error()) != 0)
00600                     throw Error(e);
00601             }
00602             cb.read();
00603         }
00604         count++;
00605     }
00606     timestop("asynchronous");
00607     printf("read %d blocks\n", count);
00608 }
00609 
00610 int main(void)
00611 {
00612     File file("tmp"), file2;
00613     ssize_t n;
00614     char buf[100];
00615     struct stat sbuf;
00616 
00617     try {
00618         sigset_test();
00619     }
00620     catch (const Error& e) {
00621         EC_EXIT(e)
00622     }
00623     try {
00624         process_test();
00625     }
00626     catch (const Error& e) {
00627         EC_EXIT(e)
00628     }
00629     process_env_test();
00630     try {
00631         aio_test();
00632     }
00633     catch (const Error& e) {
00634         if (e == ENOSYS)
00635             cout << e << endl;
00636         else
00637             EC_EXIT(e)
00638     }
00639     try {
00640         file.open(O_RDWR | O_CREAT | O_TRUNC);
00641         if (file.write("Hello", 5) != 5)
00642             throw Error(EIO);
00643         file2 = file.dup();
00644         if (file2.seek(0, SEEK_SET) != 0)
00645             throw Error(EIO);
00646         n = file2.read(buf, sizeof(buf) - 1);
00647         buf[n] = '\n';
00648         buf[n + 1] = '\0';
00649         File(STDOUT_FILENO).write(buf, n + 1);
00650         file2.stat(&sbuf);
00651         cout << "Size: " << sbuf.st_size << endl;
00652         file2.close();
00653         file2 = file.dup2(10);
00654         file2.stat(&sbuf);
00655         cout << "Size: " << sbuf.st_size << endl;
00656         file.stat(&sbuf);
00657         cout << "Size: " << sbuf.st_size << endl;
00658         File("./tmp").stat(&sbuf);
00659         cout << "Size: " << sbuf.st_size << endl;
00660         pipe_test();
00661     }
00662     catch (const Error& e) {
00663         EC_EXIT(e)
00664     }
00665     try {
00666         File myfile_in("myfifo");
00667         File myfile_out = myfile_in;
00668         try { myfile_in.unlink(); } catch (...) { };
00669         myfile_in.mkfifo();
00670         myfile_in.open(O_RDONLY | O_NONBLOCK);
00671         myfile_out.open(O_WRONLY);
00672         myfile_out.fcntl(F_SETFL, myfile_out.fcntl(F_GETFL) & ~O_NONBLOCK);
00673         char *s = "Stuff to FIFO";
00674         myfile_out.write(s, strlen(s) + 1);
00675         myfile_in.read(buf, sizeof(buf));
00676         cout << "Read from FIFO: " << buf << endl;
00677         
00678         Dir d("barfdir");
00679         cout << d << endl;
00680         EC_CATCH( d.mkdir() )
00681         cout << "dir access = " << d.access(F_OK, false) << endl;
00682         EC_CATCH( d.rmdir() )
00683         EC_CATCH( cout << "dir access = " << d.access(F_OK, false) << endl )
00684         //maybe bool with 3 errnos collected into false?
00685         //symlink subclass of file
00686     }
00687     catch (const Error& e) {
00688         EC_CAUGHT(e)
00689         exit(EXIT_FAILURE);
00690     }
00691     try {
00692         //dirstream_test();
00693     }
00694     catch (const Error& e) {
00695         EC_EXIT(e)
00696     }
00697     try {
00698         size_t n;
00699         char buf[200];
00700 
00701         n = System::confstr(_CS_PATH, buf, sizeof(buf));
00702         cout << "_CS_PATH: " << buf << " (" << n << ")" << endl;
00703         cout << "_SC_ARG_MAX: " << System::sysconf(_SC_ARG_MAX) << endl;
00704         struct utsname name;
00705         System::uname(&name);
00706         cout << "sysname: " << name.sysname << endl;
00707         cout << "nodename: " << name.nodename << endl;
00708         cout << "release: " << name.release << endl;
00709         cout << "version: " << name.version << endl;
00710         cout << "machine: " << name.machine << endl;
00711     }
00712     catch (const Error& e) {
00713         EC_EXIT(e)
00714     }
00715     try {
00716         time_test();
00717     }
00718     catch (const Error& e) {
00719         cout << e << endl;
00720         EC_EXIT(e)
00721     }
00722     try {
00723         new_time_test();
00724     }
00725     catch (const Error& e) {
00726         cout << e << endl;
00727         EC_EXIT(e)
00728     }
00729     try {
00730         socket_test_unix();
00731         socket_test_inet();
00732         sockip_test();
00733         browser_test();
00734     }
00735     catch (const Error& e) {
00736         cout << e << endl;
00737         EC_EXIT(e)
00738     }
00739     try {
00740         sysvmsg_test();
00741     }
00742     catch (const Error& e) {
00743         EC_EXIT(e)
00744     }
00745     try {
00746         sysvshm_test();
00747     }
00748     catch (const Error& e) {
00749         EC_EXIT(e)
00750     }
00751     try {
00752         sysvsem_test();
00753     }
00754     catch (const Error& e) {
00755         EC_EXIT(e)
00756     }
00757     try {
00758         posixmsg_test();
00759     }
00760     catch (const Error& e) {
00761         cout << e << endl;
00762     }
00763     try {
00764         posixsem_test();
00765     }
00766     catch (const Error& e) {
00767         cout << e << endl;
00768     }
00769     try {
00770         posixshm_test();
00771     }
00772     catch (const Error& e) {
00773         cout << e << endl;
00774     }
00775     try {
00776         terminal_test();
00777     }
00778     catch (const Error& e) {
00779         cout << e << endl;
00780         EC_EXIT(e)
00781     }
00782 
00783     exit(EXIT_SUCCESS);
00784 }

Generated on Fri Apr 23 10:57:07 2004 for AUP2 Example Source by doxygen 1.3.1