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