summaryrefslogtreecommitdiff
path: root/tests/glibmm_buildfilename/main.cc
blob: b163d7396807132a9e54fae103df0a884a8aef00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <glibmm.h>
#include <iostream>
#include <string.h>

//Use this line if you want debug output:
//std::ostream& ostr = std::cout;

//This seems nicer and more useful than putting an ifdef around the use of ostr:
std::stringstream debug;
std::ostream& ostr = debug;

#define DIR "/dir1/dir_2/dir-3"
#define FILE "dir/file.ext"

int main(int, char**)
{
  gchar* dir_1 = g_strdup(DIR);
  std::string dir_2(DIR);
  Glib::ustring dir_3(DIR);
  gchar* file_1 = g_strdup(FILE);
  std::string file_2(FILE);
  Glib::ustring file_3(FILE);

  std::string path;

  path = Glib::build_filename(dir_1, file_3);
  ostr << "Path 1: " << path << std::endl;

  path = Glib::build_filename(dir_1, dir_2, FILE);
  ostr << "Path 2: " << path << std::endl;

  path = Glib::build_filename(dir_1, dir_2, dir_3, FILE);
  ostr << "Path 3: " << path << std::endl;

  path = Glib::build_filename(dir_1, dir_2, dir_3, file_1);
  ostr << "Path 4: " << path << std::endl;

  path = Glib::build_filename(dir_1, dir_2, dir_1, dir_3, dir_2, dir_3,
    dir_1, dir_2, file_2);
  ostr << "Path 5: " << path << std::endl;

  return 0;
}