1 /* 2 * Copyright (C) 2012 Marios Makris <marios.makris (at) gmail.com> 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it would be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * Further, this software is distributed without any warranty that it is 13 * free of the rightful claim of any third person regarding infringement 14 * or the like. Any license provided herein, whether implied or 15 * otherwise, applies only to this software file. Patent licenses, if 16 * any, provided herein do not apply to combinations of this program with 17 * other software, or any other product whatsoever. 18 * 19 * You should have received a copy of the GNU General Public License along 20 * with this program; if not, write the Free Software Foundation, Inc., 21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 */ 23 24 /* 25 * Test program for the tst_tmpdir program in /lib 26 * 27 * This program creates and deletes a temporary file in order to test 28 * the functionality of the tst_tmpdir functionality. 29 * On successfull completion it prints the message: 30 * "Test completed successfully!" 31 */ 32 33 #include <stdio.h> 34 #include <errno.h> 35 36 #include "test.h" 37 38 #ifndef PATH_MAX 39 #ifdef MAXPATHLEN 40 #define PATH_MAX MAXPATHLEN 41 #else 42 #define PATH_MAX 1024 43 #endif 44 #endif 45 46 char *TCID = "tst_tmpdir_test"; 47 int TST_TOTAL = 1; 48 49 int main(void) 50 { 51 char *tmp_dir; 52 char *start_dir = getcwd(NULL, PATH_MAX); 53 char *changed_dir; 54 int fail_counter = 0; 55 56 tst_tmpdir(); 57 58 tmp_dir = tst_get_tmpdir(); 59 changed_dir = getcwd(NULL, PATH_MAX); 60 61 if (strcmp(tmp_dir, changed_dir) == 0 && 62 strcmp(tmp_dir, start_dir) != 0) { 63 printf("Temp directory successfully created and switched to\n"); 64 } else { 65 printf("Temp directory is wrong!\n"); 66 fail_counter++; 67 } 68 69 tst_rmdir(); 70 71 if (chdir(tmp_dir) == -1 && errno == ENOENT) { 72 printf("The temp directory was removed successfully\n"); 73 } else { 74 printf("Failed to remove the temp directory!\n"); 75 fail_counter++; 76 } 77 78 if (fail_counter > 0) 79 printf("Something failed please review!!\n"); 80 else 81 printf("Test completed successfully!\n"); 82 83 return 0; 84 } 85