test_0.c revision 228759
1178476Sjb/*- 2178476Sjb * Copyright (c) 2003-2007 Tim Kientzle 3178476Sjb * All rights reserved. 4178476Sjb * 5178476Sjb * Redistribution and use in source and binary forms, with or without 6178476Sjb * modification, are permitted provided that the following conditions 7178476Sjb * are met: 8178476Sjb * 1. Redistributions of source code must retain the above copyright 9178476Sjb * notice, this list of conditions and the following disclaimer. 10178476Sjb * 2. Redistributions in binary form must reproduce the above copyright 11178476Sjb * notice, this list of conditions and the following disclaimer in the 12178476Sjb * documentation and/or other materials provided with the distribution. 13178476Sjb * 14178476Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15178476Sjb * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16178476Sjb * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17178476Sjb * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18178476Sjb * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19178476Sjb * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20178476Sjb * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21178476Sjb * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22178476Sjb * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23178476Sjb * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24178476Sjb */ 25178476Sjb#include "test.h" 26178476Sjb__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_0.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); 27178476Sjb 28178476Sjb/* 29178476Sjb * This first test does basic sanity checks on the environment. For 30178476Sjb * most of these, we just exit on failure. 31178476Sjb */ 32178476Sjb#if !defined(_WIN32) || defined(__CYGWIN__) 33178476Sjb#define DEV_NULL "/dev/null" 34178476Sjb#else 35178476Sjb#define DEV_NULL "NUL" 36178476Sjb#endif 37178476Sjb 38178476SjbDEFINE_TEST(test_0) 39178476Sjb{ 40178476Sjb struct stat st; 41178476Sjb 42178476Sjb failure("File %s does not exist?!", testprog); 43178476Sjb if (!assertEqualInt(0, stat(testprogfile, &st))) 44178476Sjb exit(1); 45178476Sjb 46178476Sjb failure("%s is not executable?!", testprog); 47178476Sjb if (!assert((st.st_mode & 0111) != 0)) 48178476Sjb exit(1); 49178476Sjb 50178476Sjb /* 51178476Sjb * Try to succesfully run the program; this requires that 52178476Sjb * we know some option that will succeed. 53178476Sjb */ 54178476Sjb if (0 == systemf("%s --version >" DEV_NULL, testprog)) { 55178476Sjb /* This worked. */ 56178476Sjb } else if (0 == systemf("%s -W version >" DEV_NULL, testprog)) { 57 /* This worked. */ 58 } else { 59 failure("Unable to successfully run any of the following:\n" 60 " * %s --version\n" 61 " * %s -W version\n", 62 testprog, testprog); 63 assert(0); 64 } 65 66 /* TODO: Ensure that our reference files are available. */ 67} 68