Back to index

unity  6.0.0
test-get-transients.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Canonical Ltd.
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * Authored By:
00019  * Sam Spilsbury <sam.spilsbury@canonical.com>
00020  */
00021 #ifndef _GNU_SOURCE
00022 #define _GNU_SOURCE
00023 #endif
00024 
00025 #include <cstdio>
00026 #include <cstdlib>
00027 #include <iostream>
00028 #include <iomanip>
00029 #include <unistd.h> 
00030 #include <sstream>
00031 #include <cstring>
00032 
00033 #include <x11-window-read-transients.h>
00034 
00035 void usage ()
00036 {
00037   std::cout << "test-get-transients [WINDOW]" << std::endl;
00038 }
00039 
00040 int main (int argc, char **argv)
00041 {
00042   Display                    *dpy;
00043   Window                     xid = 0;
00044   X11WindowReadTransients    *window = NULL;
00045   X11WindowReadTransients    *transient = NULL;
00046   X11WindowReadTransients    *hasClientLeader = NULL;
00047   std::vector<unsigned int>  expectedTransients;
00048 
00049   if ((argc == 2 && std::string (argv[1]) == "--help") || argc > 3)
00050   {
00051     usage ();
00052     return 1;
00053   }
00054 
00055   dpy = XOpenDisplay (NULL);
00056 
00057   if (!dpy)
00058   {
00059     std::cerr << "Failed to open display ... setting test to passed" << std::endl;
00060     return 0;
00061   }
00062 
00063   if (argc > 1)
00064     std::stringstream (argv[1]) >> std::hex >> xid;
00065 
00066   window = new X11WindowReadTransients (dpy, xid);
00067 
00068   if (!xid)
00069   {
00070     transient = new X11WindowReadTransients (dpy, 0);
00071     hasClientLeader = new X11WindowReadTransients (dpy, 0);
00072 
00073     transient->makeTransientFor (window);
00074     window->setClientLeader (window);
00075     hasClientLeader->setClientLeader (window);
00076   }
00077 
00078   /* This assumes that compiz/X is going to process
00079    * our requests in 3 seconds. That's plenty of time */
00080 
00081   sleep (3);
00082   window->printTransients ();
00083 
00084   if (transient && hasClientLeader)
00085   {
00086     expectedTransients.push_back (transient->id ());
00087     expectedTransients.push_back (hasClientLeader->id ());
00088 
00089     if (expectedTransients != window->transients ())
00090     {
00091       delete transient;
00092       delete hasClientLeader;
00093       delete window;
00094       XCloseDisplay (dpy);
00095 
00096       std::cout << "FAIL: returned transients did not match expected transients" << std::endl;
00097       return 1;
00098     }
00099     else
00100       std::cout << "PASS: returned transients did match expected transients" << std::endl;
00101   }
00102 
00103   if (transient)
00104     delete transient;
00105 
00106   delete window;
00107 
00108   XCloseDisplay (dpy);
00109 
00110   return 0;
00111 }