dbus-misc.c
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-misc.c A few assorted public functions that don't fit elsewhere
*
* Copyright (C) 2006 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <config.h>
#include "dbus-misc.h"
#include "dbus-internals.h"
#include "dbus-string.h"
char*
dbus_get_local_machine_id (void)
{
DBusString uuid;
char *s;
s = NULL;
if (!_dbus_string_init (&uuid))
return NULL;
if (!_dbus_get_local_machine_uuid_encoded (&uuid) ||
!_dbus_string_steal_data (&uuid, &s))
{
_dbus_string_free (&uuid);
return NULL;
}
else
{
_dbus_string_free (&uuid);
return s;
}
}
void
dbus_get_version (int *major_version_p,
int *minor_version_p,
int *micro_version_p)
{
if (major_version_p)
*major_version_p = DBUS_MAJOR_VERSION;
if (minor_version_p)
*minor_version_p = DBUS_MINOR_VERSION;
if (micro_version_p)
*micro_version_p = DBUS_MICRO_VERSION;
}
/* End of public API */
#ifdef DBUS_BUILD_TESTS
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#include "dbus-test.h"
#include <stdlib.h>
dbus_bool_t
_dbus_misc_test (void)
{
int major, minor, micro;
DBusString str;
/* make sure we don't crash on NULL */
dbus_get_version (NULL, NULL, NULL);
/* Now verify that all the compile-time version stuff
* is right and matches the runtime. These tests
* are mostly intended to catch various kinds of
* typo (mixing up major and minor, that sort of thing).
*/
dbus_get_version (&major, &minor, &micro);
_dbus_assert (major == DBUS_MAJOR_VERSION);
_dbus_assert (minor == DBUS_MINOR_VERSION);
_dbus_assert (micro == DBUS_MICRO_VERSION);
#define MAKE_VERSION(x, y, z) (((x) << 16) | ((y) << 8) | (z))
/* check that MAKE_VERSION works and produces the intended ordering */
_dbus_assert (MAKE_VERSION (1, 0, 0) > MAKE_VERSION (0, 0, 0));
_dbus_assert (MAKE_VERSION (1, 1, 0) > MAKE_VERSION (1, 0, 0));
_dbus_assert (MAKE_VERSION (1, 1, 1) > MAKE_VERSION (1, 1, 0));
_dbus_assert (MAKE_VERSION (2, 0, 0) > MAKE_VERSION (1, 1, 1));
_dbus_assert (MAKE_VERSION (2, 1, 0) > MAKE_VERSION (1, 1, 1));
_dbus_assert (MAKE_VERSION (2, 1, 1) > MAKE_VERSION (1, 1, 1));
/* check DBUS_VERSION */
_dbus_assert (MAKE_VERSION (major, minor, micro) == DBUS_VERSION);
/* check that ordering works with DBUS_VERSION */
_dbus_assert (MAKE_VERSION (major - 1, minor, micro) < DBUS_VERSION);
_dbus_assert (MAKE_VERSION (major, minor - 1, micro) < DBUS_VERSION);
_dbus_assert (MAKE_VERSION (major, minor, micro - 1) < DBUS_VERSION);
_dbus_assert (MAKE_VERSION (major + 1, minor, micro) > DBUS_VERSION);
_dbus_assert (MAKE_VERSION (major, minor + 1, micro) > DBUS_VERSION);
_dbus_assert (MAKE_VERSION (major, minor, micro + 1) > DBUS_VERSION);
/* Check DBUS_VERSION_STRING */
if (!_dbus_string_init (&str))
_dbus_assert_not_reached ("no memory");
if (!(_dbus_string_append_int (&str, major) &&
_dbus_string_append_byte (&str, '.') &&
_dbus_string_append_int (&str, minor) &&
_dbus_string_append_byte (&str, '.') &&
_dbus_string_append_int (&str, micro)))
_dbus_assert_not_reached ("no memory");
_dbus_assert (_dbus_string_equal_c_str (&str, DBUS_VERSION_STRING));
_dbus_string_free (&str);
return TRUE;
}
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
#endif