示例#1
0
static void
test_address (void)
{
    QofInstance *ent;
    GncAddress *address;
    QofBook *book = qof_book_new ();

    ent = g_object_new(QOF_TYPE_INSTANCE, "guid", guid_null(), NULL);
    ent->e_type = "asdf";

    /* Test creation/destruction */
    {
        do_test (gncAddressCreate (NULL,  NULL) == NULL, "address create NULL");

        address = gncAddressCreate (book, ent);
        do_test (address != NULL, "address create");

        gncAddressBeginEdit (address);
        gncAddressDestroy (address);
        success ("create/destroy");
    }

    /* Test setting routines */
    {
        address = gncAddressCreate (book, ent);
        test_string_fcn (address, "Name", gncAddressSetName, gncAddressGetName);
        test_string_fcn (address, "Addr1", gncAddressSetAddr1, gncAddressGetAddr1);
        test_string_fcn (address, "Addr2", gncAddressSetAddr2, gncAddressGetAddr2);
        test_string_fcn (address, "Addr3", gncAddressSetAddr3, gncAddressGetAddr3);
        test_string_fcn (address, "Addr4", gncAddressSetAddr4, gncAddressGetAddr4);
        test_string_fcn (address, "Phone", gncAddressSetPhone, gncAddressGetPhone);
        test_string_fcn (address, "Fax", gncAddressSetFax, gncAddressGetFax);
        test_string_fcn (address, "Email", gncAddressSetEmail, gncAddressGetEmail);
    }
}
示例#2
0
static void
test_employee (void)
{
    QofBackend *be;
    QofBook *book;
    QofSession *session;
    GncEmployee *employee;

    session = qof_session_new();
    qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
    book = qof_session_get_book(session);
    /* The book *must* have a backend to pass the test of the 'dirty' flag */
    /* See the README file for details */

    be = qof_book_get_backend (book);

    /* Test creation/destruction */
    {
        do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL");
        employee = gncEmployeeCreate (book);
        do_test (employee != NULL, "employee create");
        do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book,
                 "getbook");

        gncEmployeeBeginEdit (employee);
        gncEmployeeDestroy (employee);
        success ("create/destroy");
    }

    /* Test setting/getting routines; does the active flag get set right? */
    {
        GncGUID guid;

        test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID);
        test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername);
        test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage);
        test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl);

        test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday);
        test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate);

        test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive);

        do_test (gncEmployeeGetAddr (employee) != NULL, "Addr");

        guid_new (&guid);
        employee = gncEmployeeCreate (book);
        count++;
        gncEmployeeSetGUID (employee, &guid);
        do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare");
    }
#if 0
    {
        GList *list;

        list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE);
        do_test (list != NULL, "getList all");
        do_test (g_list_length (list) == count, "correct length: all");
        g_list_free (list);

        list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE);
        do_test (list != NULL, "getList active");
        do_test (g_list_length (list) == 1, "correct length: active");
        g_list_free (list);
    }
#endif
    {
        const char *str = get_random_string();
        const char *res;
        GncAddress *addr;

        addr = gncEmployeeGetAddr (employee);
        gncAddressSetName (addr, str);
        res = qof_object_printable (GNC_ID_EMPLOYEE, employee);
        do_test (res != NULL, "Printable NULL?");
        do_test (safe_strcmp (str, res) == 0, "Printable equals");
    }
}
示例#3
0
static void
test_customer (void)
{
    QofBook *book;
    GncCustomer *customer;

    book = qof_book_new ();

    /* Test creation/destruction */
    {
        do_test (gncCustomerCreate (NULL) == NULL, "customer create NULL");
        customer = gncCustomerCreate (book);
        do_test (customer != NULL, "customer create");
        do_test (gncCustomerGetBook (customer) == book, "getbook");

        gncCustomerBeginEdit (customer);
        gncCustomerDestroy (customer);
        success ("create/destroy");
    }

    /* Test setting/getting routines; does the active flag get set right? */
    {
        GncGUID guid;

        test_string_fcn (book, "Id", gncCustomerSetID, gncCustomerGetID);
        test_string_fcn (book, "Name", gncCustomerSetName, gncCustomerGetName);
        test_string_fcn (book, "Notes", gncCustomerSetNotes, gncCustomerGetNotes);

        //test_string_fcn (book, "Terms", gncCustomerSetTerms, gncCustomerGetTerms);

        test_numeric_fcn (book, "Discount", gncCustomerSetDiscount, gncCustomerGetDiscount);
        test_numeric_fcn (book, "Credit", gncCustomerSetCredit, gncCustomerGetCredit);

        test_bool_fcn (book, "Active", gncCustomerSetActive, gncCustomerGetActive);

        do_test (gncCustomerGetAddr (customer) != NULL, "Addr");
        do_test (gncCustomerGetShipAddr (customer) != NULL, "ShipAddr");

        guid_replace (&guid);
        customer = gncCustomerCreate (book);
        count++;
        gncCustomerSetGUID (customer, &guid);
        do_test (guid_equal (&guid, gncCustomerGetGUID (customer)), "guid compare");
    }
    {
        GList *list;

        list = gncBusinessGetList (book, GNC_ID_CUSTOMER, TRUE);
        do_test (list != NULL, "getList all");
        do_test (g_list_length (list) == count, "correct length: all");
        g_list_free (list);

        list = gncBusinessGetList (book, GNC_ID_CUSTOMER, FALSE);
        do_test (list != NULL, "getList active");
        do_test (g_list_length (list) == 1, "correct length: active");
        g_list_free (list);
    }
    {
        const char *str = get_random_string();
        const char *res;

        res = NULL;
        gncCustomerBeginEdit(customer);
        gncCustomerSetName (customer, str);
        gncCustomerCommitEdit(customer);
        res = qof_object_printable (GNC_ID_CUSTOMER, customer);
        do_test (res != NULL, "Printable NULL?");
        do_test (g_strcmp0 (str, res) == 0, "Printable equals");
    }

    do_test (gncCustomerGetJoblist (customer, TRUE) == NULL, "joblist empty");

    /* Test the Entity Table */
    {
        const GncGUID *guid;

        guid = gncCustomerGetGUID (customer);
        do_test (gncCustomerLookup (book, guid) == customer, "Entity Table");
    }

    /* Note: JobList is tested from the Job tests */
    qof_book_destroy (book);
}
示例#4
0
static void
test_employee (void)
{
    QofBook *book;
    GncEmployee *employee;

    book = qof_book_new();

    /* Test creation/destruction */
    {
        do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL");
        employee = gncEmployeeCreate (book);
        do_test (employee != NULL, "employee create");
        do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book,
                 "getbook");

        gncEmployeeBeginEdit (employee);
        gncEmployeeDestroy (employee);
        success ("create/destroy");
    }

    /* Test setting/getting routines; does the active flag get set right? */
    {
        GncGUID guid;

        test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID);
        test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername);
        test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage);
        test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl);

        test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday);
        test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate);

        test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive);

        do_test (gncEmployeeGetAddr (employee) != NULL, "Addr");

        guid_replace (&guid);
        employee = gncEmployeeCreate (book);
        count++;
        gncEmployeeSetGUID (employee, &guid);
        do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare");
    }
    {
        GList *list;

        list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE);
        do_test (list != NULL, "getList all");
        do_test (g_list_length (list) == count, "correct length: all");
        g_list_free (list);

        list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE);
        do_test (list != NULL, "getList active");
        do_test (g_list_length (list) == 1, "correct length: active");
        g_list_free (list);
    }
    {
        const char *str = get_random_string();
        const char *res;
        GncAddress *addr;

        addr = gncEmployeeGetAddr (employee);
        gncAddressSetName (addr, str);
        res = qof_object_printable (GNC_ID_EMPLOYEE, employee);
        do_test (res != NULL, "Printable NULL?");
        do_test (g_strcmp0 (str, res) == 0, "Printable equals");
    }

    qof_book_destroy (book);
}
示例#5
0
static void
test_vendor (void)
{
    QofBook *book;
    GncVendor *vendor;

    book = qof_book_new();

    /* Test creation/destruction */
    {
        do_test (gncVendorCreate (NULL) == NULL, "vendor create NULL");
        vendor = gncVendorCreate (book);
        do_test (vendor != NULL, "vendor create");
        do_test (qof_instance_get_book (QOF_INSTANCE(vendor)) == book,
                 "getbook");

        gncVendorBeginEdit (vendor);
        gncVendorDestroy (vendor);
        success ("create/destroy");
    }

    /* Test setting/getting routines; does the active flag get set right? */
    {
        GncGUID guid;

        test_string_fcn (book, "Id", gncVendorSetID, gncVendorGetID);
        test_string_fcn (book, "Name", gncVendorSetName, gncVendorGetName);
        test_string_fcn (book, "Notes", gncVendorSetNotes, gncVendorGetNotes);

        //test_string_fcn (book, "Terms", gncVendorSetTerms, gncVendorGetTerms);

        //test_bool_fcn (book, "TaxIncluded", gncVendorSetTaxIncluded, gncVendorGetTaxIncluded);
        test_bool_fcn (book, "Active", gncVendorSetActive, gncVendorGetActive);

        do_test (gncVendorGetAddr (vendor) != NULL, "Addr");

        guid_new (&guid);
        vendor = gncVendorCreate (book);
        count++;
        gncVendorSetGUID (vendor, &guid);
        do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(vendor))), "guid compare");
    }
    {
        GList *list;

        list = gncBusinessGetList (book, GNC_ID_VENDOR, TRUE);
        do_test (list != NULL, "getList all");
        do_test (g_list_length (list) == count, "correct length: all");
        g_list_free (list);

        list = gncBusinessGetList (book, GNC_ID_VENDOR, FALSE);
        do_test (list != NULL, "getList active");
        do_test (g_list_length (list) == 1, "correct length: active");
        g_list_free (list);
    }
    {
        const char *str = get_random_string();
        const char *res;

        gncVendorSetName (vendor, str);
        res = qof_object_printable (GNC_ID_VENDOR, vendor);
        do_test (res != NULL, "Printable NULL?");
        do_test (g_strcmp0 (str, res) == 0, "Printable equals");
    }

    qof_book_destroy (book);
}