Back to index

nux  3.0.0
Helpers.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright 2011 Inalogic® Inc.
00004  *
00005  * This program is free software: you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser General Public License, as
00007  * published by the  Free Software Foundation; either version 2.1 or 3.0
00008  * of the License.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranties of
00012  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00013  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00014  * License for more details.
00015  *
00016  * You should have received a copy of both the GNU Lesser General Public
00017  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00018  *
00019  * Authored by: Tim Penhey <tim.penhey@canonical.com>
00020  *
00021  */
00022 
00023 #include "Helpers.h"
00024 
00025 #include <fstream>
00026 #include <stdexcept>
00027 
00028 namespace nux
00029 {
00030 namespace testing
00031 {
00032 
00033 std::string ReadFile(std::string const& filename)
00034 {
00035   std::ifstream input(filename.c_str());
00036   if (input.bad())
00037     throw std::runtime_error("bad file");
00038   return std::string((std::istreambuf_iterator<char>(input)),
00039                      std::istreambuf_iterator<char>());
00040 }
00041 
00042 void PumpGObjectMainLoop()
00043 {
00044   GMainContext* context(g_main_context_get_thread_default());
00045   while (g_main_context_pending(context)) {
00046     g_main_context_iteration(context, false);
00047   }
00048 }
00049 
00050 
00051 }
00052 }