/* Build like so:
 * gcc test_libgda.c `pkg-config libgda-5.0 --cflags --libs`
 */

#include <libgda/libgda.h>
#include <locale.h>
#include <stdio.h>
#include <iostream>
#include <stdexcept>

GdaConnection* conn = NULL;


int main()
{
  try
  {
    std::locale::global(std::locale(""));
  }
  catch(const std::runtime_error& ex)
  {
    //This has been known to throw an exception at least once:
    //https://bugzilla.gnome.org/show_bug.cgi?id=619445
    //This should tell us what the problem is:
    std::cerr << G_STRFUNC << ": exception from std::locale::global(std::locale(\"\")): " << ex.what() << std::endl;
    std::cerr << G_STRFUNC << ":   This can happen if the locale is not properly installed or configured." << std::endl;
  }

  gda_init();

  /* Comment this out to fix the problem: */
  setlocale (LC_ALL, "");

  const double expected = 3.49f;

  GdaNumeric* numeric = gda_numeric_new();
  gda_numeric_set_double(numeric, expected);

  const double result = gda_numeric_get_double(numeric);

  printf("expected: %f, result=%f\n", expected, result);

  return (expected == result) ? EXIT_SUCCESS : EXIT_FAILURE;
}

