1192
1235
g_object_unref (client);
1239
* colord_get_profile_destination:
1242
colord_get_profile_destination (GFile *file)
1248
g_return_val_if_fail (file != NULL, NULL);
1250
/* get destination filename for this source file */
1251
basename = g_file_get_basename (file);
1252
destination = g_build_filename (g_get_user_data_dir (), "icc", basename, NULL);
1253
dest = g_file_new_for_path (destination);
1256
g_free (destination);
1261
colord_client_import_func (void)
1265
CdProfile *profile2;
1268
GFile *invalid_file;
1270
GError *error = NULL;
1271
gchar full_path[PATH_MAX];
1274
/* no running colord to use */
1275
if (!has_colord_process) {
1276
g_print ("[DISABLED] ");
1281
client = cd_client_new ();
1282
g_assert (client != NULL);
1285
ret = cd_client_connect_sync (client, NULL, &error);
1286
g_assert_no_error (error);
1289
/* check we can't import random files */
1290
realpath (TESTDATADIR "/Makefile.am", full_path);
1291
invalid_file = g_file_new_for_path (full_path);
1292
profile2 = cd_client_import_profile_sync (client,
1296
g_assert_error (error,
1298
CD_CLIENT_ERROR_FILE_INVALID);
1299
g_assert (profile2 == NULL);
1300
g_clear_error (&error);
1302
/* create extra profile */
1303
realpath (TESTDATADIR "/ibm-t61.icc", full_path);
1304
file = g_file_new_for_path (full_path);
1306
/* ensure it's deleted */
1307
dest = colord_get_profile_destination (file);
1308
if (g_file_query_exists (dest, NULL)) {
1309
ret = g_file_delete (dest, NULL, &error);
1310
g_assert_no_error (error);
1313
/* wait for daemon to DTRT */
1314
_g_test_loop_run_with_timeout (2000);
1318
profile = cd_client_import_profile_sync (client,
1322
g_assert_no_error (error);
1323
g_assert (profile != NULL);
1326
ret = cd_profile_connect_sync (profile, NULL, &error);
1327
g_assert_no_error (error);
1330
/* make sure it's now installed in the right place */
1331
dest_path = g_file_get_path (dest);
1332
g_assert_cmpstr (cd_profile_get_filename (profile), ==, dest_path);
1334
/* make sure we can't import it again */
1335
profile2 = cd_client_import_profile_sync (client,
1339
g_assert_error (error, CD_CLIENT_ERROR, CD_CLIENT_ERROR_ALREADY_EXISTS);
1340
g_assert (profile2 == NULL);
1341
g_clear_error (&error);
1344
ret = g_file_delete (dest, NULL, &error);
1345
g_assert_no_error (error);
1349
g_object_unref (invalid_file);
1350
g_object_unref (file);
1351
g_object_unref (dest);
1352
g_object_unref (profile);
1353
g_object_unref (client);
1196
1357
colord_delete_profile_good_cb (GObject *object, GAsyncResult *res, gpointer user_data)
1492
1697
g_object_unref (client);
1700
/* when we re-add profiles, ensure they are sorted so the newest
1701
* assigned profile is first, not the newest-added */
1703
colord_profile_ordering_func (void)
1707
CdProfile *profile_tmp;
1708
CdProfile *profile1;
1709
CdProfile *profile2;
1711
GError *error = NULL;
1715
/* no running colord to use */
1716
if (!has_colord_process) {
1717
g_print ("[DISABLED] ");
1722
client = cd_client_new ();
1723
g_assert (client != NULL);
1726
device_id = colord_get_random_device_id ();
1727
device = cd_client_create_device_sync (client,
1729
CD_OBJECT_SCOPE_TEMP,
1733
g_assert_no_error (error);
1734
g_assert (device != NULL);
1737
ret = cd_device_connect_sync (device, NULL, &error);
1738
g_assert_no_error (error);
1741
g_assert_cmpstr (cd_device_get_id (device), ==, device_id);
1743
/* get new number of profiles */
1744
array = cd_device_get_profiles (device);
1745
g_assert (array != NULL);
1746
g_assert_cmpint (array->len, ==, 0);
1747
g_ptr_array_unref (array);
1749
/* create older profile */
1750
profile2 = cd_client_create_profile_sync (client,
1752
CD_OBJECT_SCOPE_TEMP,
1756
g_assert_no_error (error);
1757
g_assert (profile2 != NULL);
1759
/* assign profile to device */
1760
ret = cd_device_add_profile_sync (device,
1761
CD_DEVICE_RELATION_HARD,
1765
g_assert_no_error (error);
1768
/* create newer profile */
1769
profile1 = cd_client_create_profile_sync (client,
1771
CD_OBJECT_SCOPE_TEMP,
1775
g_assert_no_error (error);
1776
g_assert (profile1 != NULL);
1778
/* assign profile to device */
1779
ret = cd_device_add_profile_sync (device,
1780
CD_DEVICE_RELATION_HARD,
1784
g_assert_no_error (error);
1787
/* wait for daemon */
1788
_g_test_loop_run_with_timeout (50);
1789
_g_test_loop_quit ();
1791
/* get new number of profiles */
1792
array = cd_device_get_profiles (device);
1793
g_assert (array != NULL);
1794
g_assert_cmpint (array->len, ==, 2);
1795
profile_tmp = CD_PROFILE (g_ptr_array_index (array, 0));
1796
g_assert_cmpstr (cd_profile_get_object_path (profile_tmp),
1798
"/org/freedesktop/ColorManager/profiles/profile1");
1799
profile_tmp = CD_PROFILE (g_ptr_array_index (array, 1));
1800
g_assert_cmpstr (cd_profile_get_object_path (profile_tmp),
1802
"/org/freedesktop/ColorManager/profiles/profile2");
1803
g_ptr_array_unref (array);
1805
/* delete profiles */
1806
ret = cd_client_delete_profile_sync (client, profile1, NULL, &error);
1807
g_assert_no_error (error);
1809
ret = cd_client_delete_profile_sync (client, profile2, NULL, &error);
1810
g_assert_no_error (error);
1813
/* wait for daemon */
1814
_g_test_loop_run_with_timeout (50);
1815
_g_test_loop_quit ();
1817
/* get new number of profiles */
1818
array = cd_device_get_profiles (device);
1819
g_assert (array != NULL);
1820
g_assert_cmpint (array->len, ==, 0);
1821
g_ptr_array_unref (array);
1823
/* done with profiles */
1824
g_object_unref (profile1);
1825
g_object_unref (profile2);
1827
/* create newer profile */
1828
profile1 = cd_client_create_profile_sync (client,
1830
CD_OBJECT_SCOPE_TEMP,
1834
g_assert_no_error (error);
1835
g_assert (profile1 != NULL);
1837
/* wait for daemon */
1838
_g_test_loop_run_with_timeout (50);
1839
_g_test_loop_quit ();
1841
/* get new number of profiles */
1842
array = cd_device_get_profiles (device);
1843
g_assert (array != NULL);
1844
g_assert_cmpint (array->len, ==, 1);
1845
profile_tmp = CD_PROFILE (g_ptr_array_index (array, 0));
1846
g_assert_cmpstr (cd_profile_get_object_path (profile_tmp),
1848
"/org/freedesktop/ColorManager/profiles/profile1");
1849
g_ptr_array_unref (array);
1851
/* create older profile */
1852
profile2 = cd_client_create_profile_sync (client,
1854
CD_OBJECT_SCOPE_TEMP,
1858
g_assert_no_error (error);
1859
g_assert (profile2 != NULL);
1861
/* wait for daemon */
1862
_g_test_loop_run_with_timeout (50);
1863
_g_test_loop_quit ();
1865
/* get new number of profiles */
1866
array = cd_device_get_profiles (device);
1867
g_assert (array != NULL);
1868
g_assert_cmpint (array->len, ==, 2);
1869
profile_tmp = CD_PROFILE (g_ptr_array_index (array, 0));
1870
g_assert_cmpstr (cd_profile_get_object_path (profile_tmp),
1872
"/org/freedesktop/ColorManager/profiles/profile1");
1873
profile_tmp = CD_PROFILE (g_ptr_array_index (array, 1));
1874
g_assert_cmpstr (cd_profile_get_object_path (profile_tmp),
1876
"/org/freedesktop/ColorManager/profiles/profile2");
1877
g_ptr_array_unref (array);
1880
g_object_unref (profile1);
1881
g_object_unref (profile2);
1882
g_object_unref (device);
1883
g_object_unref (client);
1886
/* ensure duplicate profiles have the correct error code */
1888
colord_profile_duplicate_func (void)
1891
CdProfile *profile1;
1892
CdProfile *profile2;
1894
gchar full_path[PATH_MAX];
1895
GError *error = NULL;
1896
GHashTable *profile_props;
1898
/* no running colord to use */
1899
if (!has_colord_process) {
1900
g_print ("[DISABLED] ");
1905
client = cd_client_new ();
1906
g_assert (client != NULL);
1908
/* create extra profile */
1909
realpath (TESTDATADIR "/ibm-t61.icc", full_path);
1910
profile_props = g_hash_table_new_full (g_str_hash, g_str_equal,
1912
g_hash_table_insert (profile_props,
1913
g_strdup ("Filename"),
1914
g_strdup (full_path));
1916
/* create profile */
1917
profile2 = cd_client_create_profile_sync (client,
1918
"profile_duplicate",
1919
CD_OBJECT_SCOPE_TEMP,
1923
g_assert_no_error (error);
1924
g_assert (profile2 != NULL);
1926
/* create same profile */
1927
profile1 = cd_client_create_profile_sync (client,
1928
"profile_duplicate",
1929
CD_OBJECT_SCOPE_TEMP,
1933
g_assert_error (error,
1935
CD_CLIENT_ERROR_ALREADY_EXISTS);
1936
g_assert (profile1 == NULL);
1937
g_clear_error (&error);
1939
/* delete profile */
1940
ret = cd_client_delete_profile_sync (client,
1944
g_assert_no_error (error);
1947
g_hash_table_unref (profile_props);
1948
g_object_unref (profile2);
1949
g_object_unref (client);
1953
colord_device_duplicate_func (void)
1958
GError *error = NULL;
1961
/* no running colord to use */
1962
if (!has_colord_process) {
1963
g_print ("[DISABLED] ");
1968
client = cd_client_new ();
1969
g_assert (client != NULL);
1972
device_id = colord_get_random_device_id ();
1973
device1 = cd_client_create_device_sync (client,
1975
CD_OBJECT_SCOPE_TEMP,
1979
g_assert_no_error (error);
1980
g_assert (device1 != NULL);
1982
/* create duplicate device */
1983
device2 = cd_client_create_device_sync (client,
1985
CD_OBJECT_SCOPE_TEMP,
1989
g_assert_error (error,
1991
CD_CLIENT_ERROR_ALREADY_EXISTS);
1992
g_assert (device2 == NULL);
1993
g_clear_error (&error);
1996
g_object_unref (device1);
1997
g_object_unref (client);
1496
2001
main (int argc, char **argv)