dbus-misc.c

00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 /* dbus-misc.c  A few assorted public functions that don't fit elsewhere
00003  *
00004  * Copyright (C) 2006 Red Hat, Inc.
00005  *
00006  * Licensed under the Academic Free License version 2.1
00007  * 
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  * 
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 #include <config.h>
00025 #include "dbus-misc.h"
00026 #include "dbus-internals.h"
00027 #include "dbus-string.h"
00028 
00072 char*
00073 dbus_get_local_machine_id (void)
00074 {
00075   DBusString uuid;
00076   char *s;
00077 
00078   s = NULL;
00079   _dbus_string_init (&uuid);
00080   if (!_dbus_get_local_machine_uuid_encoded (&uuid) ||
00081       !_dbus_string_steal_data (&uuid, &s))
00082     {
00083       _dbus_string_free (&uuid);
00084       return FALSE;
00085     }
00086   else
00087     {
00088       _dbus_string_free (&uuid);
00089       return s;
00090     }
00091 
00092 }
00093 
00157 void
00158 dbus_get_version (int *major_version_p,
00159                   int *minor_version_p,
00160                   int *micro_version_p)
00161 {
00162   if (major_version_p)
00163     *major_version_p = DBUS_MAJOR_VERSION;
00164   if (minor_version_p)
00165     *minor_version_p = DBUS_MINOR_VERSION;
00166   if (micro_version_p)
00167     *micro_version_p = DBUS_MICRO_VERSION;
00168 }
00169 
00170  /* End of public API */
00172 
00173 #ifdef DBUS_BUILD_TESTS
00174 
00175 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00176 
00177 #include "dbus-test.h"
00178 #include <stdlib.h>
00179 
00180 
00181 dbus_bool_t
00182 _dbus_misc_test (void)
00183 {
00184   int major, minor, micro;
00185   DBusString str;
00186 
00187   /* make sure we don't crash on NULL */
00188   dbus_get_version (NULL, NULL, NULL);
00189 
00190   /* Now verify that all the compile-time version stuff
00191    * is right and matches the runtime. These tests
00192    * are mostly intended to catch various kinds of
00193    * typo (mixing up major and minor, that sort of thing).
00194    */
00195   dbus_get_version (&major, &minor, &micro);
00196 
00197   _dbus_assert (major == DBUS_MAJOR_VERSION);
00198   _dbus_assert (minor == DBUS_MINOR_VERSION);
00199   _dbus_assert (micro == DBUS_MICRO_VERSION);
00200 
00201 #define MAKE_VERSION(x, y, z) (((x) << 16) | ((y) << 8) | (z))
00202 
00203   /* check that MAKE_VERSION works and produces the intended ordering */
00204   _dbus_assert (MAKE_VERSION (1, 0, 0) > MAKE_VERSION (0, 0, 0));
00205   _dbus_assert (MAKE_VERSION (1, 1, 0) > MAKE_VERSION (1, 0, 0));
00206   _dbus_assert (MAKE_VERSION (1, 1, 1) > MAKE_VERSION (1, 1, 0));
00207 
00208   _dbus_assert (MAKE_VERSION (2, 0, 0) > MAKE_VERSION (1, 1, 1));
00209   _dbus_assert (MAKE_VERSION (2, 1, 0) > MAKE_VERSION (1, 1, 1));
00210   _dbus_assert (MAKE_VERSION (2, 1, 1) > MAKE_VERSION (1, 1, 1));
00211 
00212   /* check DBUS_VERSION */
00213   _dbus_assert (MAKE_VERSION (major, minor, micro) == DBUS_VERSION);
00214 
00215   /* check that ordering works with DBUS_VERSION */
00216   _dbus_assert (MAKE_VERSION (major - 1, minor, micro) < DBUS_VERSION);
00217   _dbus_assert (MAKE_VERSION (major, minor - 1, micro) < DBUS_VERSION);
00218   _dbus_assert (MAKE_VERSION (major, minor, micro - 1) < DBUS_VERSION);
00219   
00220   _dbus_assert (MAKE_VERSION (major + 1, minor, micro) > DBUS_VERSION);
00221   _dbus_assert (MAKE_VERSION (major, minor + 1, micro) > DBUS_VERSION);
00222   _dbus_assert (MAKE_VERSION (major, minor, micro + 1) > DBUS_VERSION);
00223 
00224   /* Check DBUS_VERSION_STRING */
00225 
00226   if (!_dbus_string_init (&str))
00227     _dbus_assert_not_reached ("no memory");
00228 
00229   if (!(_dbus_string_append_int (&str, major) &&
00230         _dbus_string_append_byte (&str, '.') &&
00231         _dbus_string_append_int (&str, minor) &&
00232         _dbus_string_append_byte (&str, '.') &&
00233         _dbus_string_append_int (&str, micro)))
00234     _dbus_assert_not_reached ("no memory");
00235 
00236   _dbus_assert (_dbus_string_equal_c_str (&str, DBUS_VERSION_STRING));
00237 
00238   _dbus_string_free (&str);
00239    
00240   return TRUE;
00241 }
00242 
00243 #endif /* !DOXYGEN_SHOULD_SKIP_THIS */
00244 
00245 #endif

Generated on Wed Aug 29 12:15:03 2007 for D-Bus by  doxygen 1.5.2