|
Freya
0.0.1
A Gtk3 MPD Client
|
00001 /*********************************************************** 00002 * This file is part of Freya 00003 * - A free MPD Gtk3 MPD Client - 00004 * 00005 * Authors: Christopher Pahl, Christoph Piechula, 00006 * Eduard Schneider 00007 * 00008 * Copyright (C) [2011-2012] 00009 * Hosted at: https://github.com/studentkittens/Freya 00010 * 00011 * __..--''``---....___ _..._ __ 00012 * /// //_.-' .-/"; ` ``<._ ``.''_ `. / // / 00013 * ///_.-' _..--.'_ `( ) ) // // 00014 * / (_..-' // (< _ ;_..__ ; `' / /// 00015 * / // // // `-._,_)' // / ``--...____..-' /// / // 00016 * Ascii-Art by Felix Lee <flee@cse.psu.edu> 00017 * 00018 * Freya is free software: you can redistribute it and/or modify 00019 * it under the terms of the GNU General Public License as published by 00020 * the Free Software Foundation, either version 3 of the License, or 00021 * (at your option) any later version. 00022 * 00023 * Freya is distributed in the hope that it will be useful, 00024 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00025 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00026 * GNU General Public License for more details. 00027 * 00028 * You should have received a copy of the GNU General Public License 00029 * along with Freya. If not, see <http://www.gnu.org/licenses/>. 00030 **************************************************************/ 00031 /* Sample test */ 00032 #include <cxxtest/TestSuite.h> 00033 #include "Writer.hh" 00034 #include "../Init/Path.hh" 00035 #include <cstring> 00036 #include <glib.h> 00037 #include <glib/gstdio.h> 00038 00039 00040 /* The whole suite. One suit for each module. */ 00041 class LogTestSuite : public CxxTest::TestSuite 00042 { 00043 public: 00044 /* some blackbox testing of log::writer */ 00045 void testLogWriter( void ) 00046 { 00047 Init::Path path; 00048 Glib::ustring LogPath = path.path_to_log(); 00049 int aval = 0; 00050 long fsize_a,fsize_b = 0; 00051 GStatBuf statbuf; 00052 memset(&statbuf,0,sizeof(GStatBuf)); 00053 00054 /* gets a logwriter instance, should create a log if not avaiable */ 00055 Log::Writer::instance(); 00056 aval = g_stat(LogPath.c_str(),&statbuf); 00057 00058 if(aval != -1) 00059 { 00060 fsize_a = statbuf.st_size; 00061 fsize_b = statbuf.st_size; 00062 00063 /* log size equal? */ 00064 TS_ASSERT_EQUALS(fsize_a,fsize_b); 00065 00066 /* writing a message to log, messeage should grow by 12 bytes + 64 bytes date/log footprint */ 00067 Info("test message"); 00068 00069 /*reinit stat struct and get new filesize */ 00070 g_stat(LogPath.c_str(),&statbuf); 00071 fsize_b = statbuf.st_size; 00072 00073 /* file_b bigger after writing to log? */ 00074 TS_ASSERT(fsize_a < fsize_b); 00075 00076 /* file_b size increased properly? file_a + written bytes? */ 00077 TS_ASSERT(fsize_a+12+64 == fsize_b); 00078 00079 /* Test if Info gets written out */ 00080 LogSetVerbosity(Log::LOG_WARN); 00081 Info("Should not be written to log"); 00082 g_stat(LogPath.c_str(),&statbuf); 00083 TS_ASSERT(fsize_b == statbuf.st_size); 00084 Warning("Should be written to log"); 00085 g_stat(LogPath.c_str(),&statbuf); 00086 TS_ASSERT(fsize_b < statbuf.st_size); 00087 } 00088 else 00089 { 00090 TS_FAIL("error occured, logfile possibly not avaiable."); 00091 } 00092 } 00093 00094 };
1.8.0