From 8641c14fd62a1d7749b30f32b067c68a209a7a24 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sat, 23 Jul 2022 21:10:43 +0200 Subject: [PATCH 1/2] spec: Add an kind to requires/recommends/supports This allows apps to specify whether they require the internet to work, or whether they explicitly work fully without internet. Signed-off-by: Philip Withnall Fixes: #343 --- docs/xml/metainfo-component.xml | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/docs/xml/metainfo-component.xml b/docs/xml/metainfo-component.xml index 9a0c0fc5..22461d5d 100644 --- a/docs/xml/metainfo-component.xml +++ b/docs/xml/metainfo-component.xml @@ -1106,6 +1106,58 @@ + + <internet/> + + + Require, recommend or support connectivity to the internet. The value of this item one of the following: + + + always - Needs internet connectivity to work. If used in a recommends element, then this indicates that the app can work without internet, but the experience will be significantly degraded. + offline-only - Never uses the internet, even if it’s available. + first-run - Uses the internet the first time the application is run, but not normally afterwards. + + + If the value of <internet/> is not offline-only, the bandwidth_mbitps attribute can be + set to a bandwidth (in Mbit/s) which is the minimum internet bandwidth needed for the application to be usable. If this attribute is not set, it’s + assumed that the application is usable with all internet connections. + + + Examples: + + + + always + + + + + always + + + + + never + + + + + first-run + + + + + always + + + + + first-run +]]> + Valid for: requires, recommends, supports + + + From 901a5cca0476c82e74fda8a65b8bc062c03b0634 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sat, 23 Jul 2022 21:20:48 +0200 Subject: [PATCH 2/2] as-relation: Add support for the new requires/recommends kind Includes tests for the XML and YAML implementations. Signed-off-by: Philip Withnall Fixes: #343 --- src/as-relation.c | 177 ++++++++++++++++++++++++++++++++++++++++++ src/as-relation.h | 33 ++++++++ tests/test-xmldata.c | 52 ++++++++++++- tests/test-yamldata.c | 55 ++++++++++++- 4 files changed, 310 insertions(+), 7 deletions(-) diff --git a/src/as-relation.c b/src/as-relation.c index 7e5e5a60..ae49d1ed 100644 --- a/src/as-relation.c +++ b/src/as-relation.c @@ -50,6 +50,9 @@ typedef struct /* specific to "display_length" relations */ AsDisplaySideKind display_side_kind; AsDisplayLengthKind display_length_kind; + + /* specific to "internet" relations */ + guint bandwidth_mbitps; } AsRelationPrivate; G_DEFINE_TYPE_WITH_PRIVATE (AsRelation, as_relation, G_TYPE_OBJECT) @@ -129,6 +132,8 @@ as_relation_item_kind_to_string (AsRelationItemKind kind) return "display_length"; if (kind == AS_RELATION_ITEM_KIND_HARDWARE) return "hardware"; + if (kind == AS_RELATION_ITEM_KIND_INTERNET) + return "internet"; return "unknown"; } @@ -161,6 +166,8 @@ as_relation_item_kind_from_string (const gchar *kind_str) return AS_RELATION_ITEM_KIND_DISPLAY_LENGTH; if (g_strcmp0 (kind_str, "hardware") == 0) return AS_RELATION_ITEM_KIND_HARDWARE; + if (g_strcmp0 (kind_str, "internet") == 0) + return AS_RELATION_ITEM_KIND_INTERNET; return AS_RELATION_ITEM_KIND_UNKNOWN; } @@ -488,6 +495,50 @@ as_display_length_kind_to_string (AsDisplayLengthKind kind) return "unknown"; } +/** + * as_internet_kind_from_string: + * @kind_str: the string. + * + * Converts the text representation to an enumerated value. + * + * Returns: a #AsInternetKind or %AS_INTERNET_KIND_UNKNOWN for unknown + * + * Since: 0.15.5 + **/ +AsInternetKind +as_internet_kind_from_string (const gchar *kind_str) +{ + if (g_strcmp0 (kind_str, "always") == 0) + return AS_INTERNET_KIND_ALWAYS; + if (g_strcmp0 (kind_str, "offline-only") == 0) + return AS_INTERNET_KIND_OFFLINE_ONLY; + if (g_strcmp0 (kind_str, "first-run") == 0) + return AS_INTERNET_KIND_FIRST_RUN; + return AS_INTERNET_KIND_UNKNOWN; +} + +/** + * as_internet_kind_to_string: + * @kind: the #AsInternetKind. + * + * Converts the enumerated value to a text representation. + * + * Returns: string version of @kind + * + * Since: 0.15.5 + **/ +const gchar * +as_internet_kind_to_string (AsInternetKind kind) +{ + if (kind == AS_INTERNET_KIND_ALWAYS) + return "always"; + if (kind == AS_INTERNET_KIND_OFFLINE_ONLY) + return "offline-only"; + if (kind == AS_INTERNET_KIND_FIRST_RUN) + return "first-run"; + return "unknown"; +} + /** * as_relation_finalize: **/ @@ -806,6 +857,93 @@ as_relation_set_value_control_kind (AsRelation *relation, AsControlKind kind) as_relation_set_value_var (relation, g_variant_new_int32 (kind)); } +/** + * as_relation_get_value_internet_kind: + * @relation: an #AsRelation instance. + * + * Get the value of this #AsRelation item as #AsInternetKind if the + * type of this relation is %AS_RELATION_ITEM_KIND_INTERNET. + * Otherwise return %AS_INTERNET_KIND_UNKNOWN + * + * Returns: a #AsInternetKind or %AS_INTERNET_KIND_UNKNOWN in case the item is not of the right kind. + * + * Since: 0.15.5 + **/ +AsInternetKind +as_relation_get_value_internet_kind (AsRelation *relation) +{ + AsRelationPrivate *priv = GET_PRIVATE (relation); + if (priv->item_kind != AS_RELATION_ITEM_KIND_INTERNET) + return AS_INTERNET_KIND_UNKNOWN; + if (priv->value == NULL) + return AS_INTERNET_KIND_UNKNOWN; + return (AsInternetKind) g_variant_get_int32 (priv->value); +} + +/** + * as_relation_set_value_internet_kind: + * @relation: an #AsRelation instance. + * @kind: an #AsInternetKind + * + * Set relation item value from an #AsInternetKind. + * + * Since: 0.15.5 + **/ +void +as_relation_set_value_internet_kind (AsRelation *relation, AsInternetKind kind) +{ + as_relation_set_value_var (relation, g_variant_new_int32 (kind)); +} + +/** + * as_relation_get_value_internet_bandwidth: + * @relation: an #AsRelation instance. + * + * If this #AsRelation is of kind %AS_RELATION_ITEM_KIND_INTERNET, return the + * minimum bandwidth requirement of the component, if set. + * + * If the relation is of a different kind, or the requirement isn’t set, this + * returns `0`. + * + * Returns: The minimum bandwidth requirement, in Mbit/s. + * Since: 0.15.5 + */ +guint +as_relation_get_value_internet_bandwidth (AsRelation *relation) +{ + AsRelationPrivate *priv = GET_PRIVATE (relation); + + if (priv->item_kind != AS_RELATION_ITEM_KIND_INTERNET) + return 0; + + return priv->bandwidth_mbitps; +} + +/** + * as-relation_set_value_internet_bandwidth: + * @relation: an #AsRelation instance. + * @bandwidth_mbitps: Minimum bandwidth requirement, in Mbit/s, or `0` for no + * requirement. + * + * Sets the minimum bandwidth requirement of the component. + * + * This requires the relation to be of item kind + * %AS_RELATION_ITEM_KIND_INTERNET. + * + * Since: 0.15.5 + */ +void +as_relation_set_value_internet_bandwidth (AsRelation *relation, + guint bandwidth_mbitps) +{ + AsRelationPrivate *priv = GET_PRIVATE (relation); + + if (priv->item_kind != AS_RELATION_ITEM_KIND_INTERNET) + return; + + priv->bandwidth_mbitps = bandwidth_mbitps; +} + /** * as_relation_get_value_px: * @relation: an #AsRelation instance. @@ -1036,6 +1174,8 @@ as_relation_load_from_xml (AsRelation *relation, AsContext *ctx, xmlNode *node, } else if (priv->item_kind == AS_RELATION_ITEM_KIND_CONTROL) { as_relation_set_value_var (relation, g_variant_new_int32 (as_control_kind_from_string (content))); + } else if (priv->item_kind == AS_RELATION_ITEM_KIND_INTERNET) { + as_relation_set_value_var (relation, g_variant_new_int32 (as_internet_kind_from_string (content))); } else { as_relation_set_value_str (relation, content); } @@ -1044,6 +1184,16 @@ as_relation_load_from_xml (AsRelation *relation, AsContext *ctx, xmlNode *node, g_autofree gchar *side_str = (gchar*) xmlGetProp (node, (xmlChar*) "side"); priv->display_side_kind = as_display_side_kind_from_string (side_str); + g_free (priv->version); + priv->version = NULL; + } else if (priv->item_kind == AS_RELATION_ITEM_KIND_INTERNET) { + g_autofree gchar *bandwidth_str = (gchar*) xmlGetProp (node, (xmlChar*) "bandwidth_mbitps"); + + if (bandwidth_str != NULL) + priv->bandwidth_mbitps = g_ascii_strtoll (bandwidth_str, NULL, 10); + else + priv->bandwidth_mbitps = 0; + g_free (priv->version); priv->version = NULL; } else if (priv->item_kind != AS_RELATION_ITEM_KIND_CONTROL) { @@ -1101,6 +1251,11 @@ as_relation_to_xml_node (AsRelation *relation, AsContext *ctx, xmlNode *root) (xmlChar*) as_relation_item_kind_to_string (priv->item_kind), (xmlChar*) as_control_kind_to_string (as_relation_get_value_control_kind (relation))); + } else if (priv->item_kind == AS_RELATION_ITEM_KIND_INTERNET) { + n = xmlNewTextChild (root, NULL, + (xmlChar*) as_relation_item_kind_to_string (priv->item_kind), + (xmlChar*) as_internet_kind_to_string (as_relation_get_value_internet_kind (relation))); + } else { n = xmlNewTextChild (root, NULL, (xmlChar*) as_relation_item_kind_to_string (priv->item_kind), @@ -1115,6 +1270,13 @@ as_relation_to_xml_node (AsRelation *relation, AsContext *ctx, xmlNode *root) xmlNewProp (n, (xmlChar*) "compare", (xmlChar*) as_relation_compare_to_string (priv->compare)); + } else if (priv->item_kind == AS_RELATION_ITEM_KIND_INTERNET) { + if (priv->bandwidth_mbitps > 0) { + g_autofree gchar *bandwidth_str = g_strdup_printf ("%u", priv->bandwidth_mbitps); + xmlNewProp (n, (xmlChar*) "bandwidth_mbitps", + (xmlChar*) bandwidth_str); + } + } else if ((priv->item_kind == AS_RELATION_ITEM_KIND_CONTROL) || (priv->item_kind == AS_RELATION_ITEM_KIND_MEMORY)) { } else if (priv->version != NULL) { xmlNewProp (n, @@ -1161,6 +1323,8 @@ as_relation_load_from_yaml (AsRelation *relation, AsContext *ctx, GNode *node, G g_strstrip (priv->version); } else if (g_strcmp0 (entry, "side") == 0) { priv->display_side_kind = as_display_side_kind_from_string (as_yaml_node_get_value (n)); + } else if (g_strcmp0 (entry, "bandwidth_mbitps") == 0) { + priv->bandwidth_mbitps = g_ascii_strtoll (as_yaml_node_get_value (n), NULL, 10); } else { AsRelationItemKind kind = as_relation_item_kind_from_string (entry); if (kind == AS_RELATION_ITEM_KIND_UNKNOWN) { @@ -1204,6 +1368,10 @@ as_relation_load_from_yaml (AsRelation *relation, AsContext *ctx, GNode *node, G as_relation_set_value_var (relation, g_variant_new_int32 (as_control_kind_from_string (as_yaml_node_get_value (n)))); + } else if (kind == AS_RELATION_ITEM_KIND_INTERNET) { + as_relation_set_value_var (relation, + g_variant_new_int32 (as_internet_kind_from_string (as_yaml_node_get_value (n)))); + } else { as_relation_set_value_str (relation, as_yaml_node_get_value (n)); } @@ -1268,6 +1436,15 @@ as_relation_emit_yaml (AsRelation *relation, AsContext *ctx, yaml_emitter_t *emi as_relation_item_kind_to_string (priv->item_kind), as_relation_get_value_int (relation)); + } else if (priv->item_kind == AS_RELATION_ITEM_KIND_INTERNET) { + as_yaml_emit_entry (emitter, + as_relation_item_kind_to_string (priv->item_kind), + as_internet_kind_to_string (as_relation_get_value_internet_kind (relation))); + if (priv->bandwidth_mbitps > 0) + as_yaml_emit_entry_uint64 (emitter, + "bandwidth_mbitps", + priv->bandwidth_mbitps); + } else { as_yaml_emit_entry (emitter, as_relation_item_kind_to_string (priv->item_kind), diff --git a/src/as-relation.h b/src/as-relation.h index bfac725c..d7110b27 100644 --- a/src/as-relation.h +++ b/src/as-relation.h @@ -73,6 +73,7 @@ typedef enum { * @AS_RELATION_ITEM_KIND_CONTROL: An input method for users to control software * @AS_RELATION_ITEM_KIND_DISPLAY_LENGTH: Display edge length * @AS_RELATION_ITEM_KIND_HARDWARE: A Computer Hardware ID (CHID) to depend on system hardware + * @AS_RELATION_ITEM_KIND_INTERNET: Internet connectivity (Since: 0.15.5) * * Type of the item an #AsRelation is for. **/ @@ -86,6 +87,7 @@ typedef enum { AS_RELATION_ITEM_KIND_CONTROL, AS_RELATION_ITEM_KIND_DISPLAY_LENGTH, AS_RELATION_ITEM_KIND_HARDWARE, + AS_RELATION_ITEM_KIND_INTERNET, /*< private >*/ AS_RELATION_ITEM_KIND_LAST } AsRelationItemKind; @@ -182,6 +184,27 @@ typedef enum { AS_DISPLAY_LENGTH_KIND_LAST } AsDisplayLengthKind; +/** + * AsInternetKind: + * @AS_INTERNET_KIND_UNKNOWN: Unknown + * @AS_INTERNET_KIND_ALWAYS: Always requires/recommends internet + * @AS_INTERNET_KIND_OFFLINE_ONLY: Application is offline-only + * @AS_INTERNET_KIND_FIRST_RUN: Requires/Recommends internet on first run only + * + * Different internet connectivity requirements or recommendations for an + * application. + * + * Since: 0.15.5 + **/ +typedef enum { + AS_INTERNET_KIND_UNKNOWN, + AS_INTERNET_KIND_ALWAYS, + AS_INTERNET_KIND_OFFLINE_ONLY, + AS_INTERNET_KIND_FIRST_RUN, + /*< private >*/ + AS_INTERNET_KIND_LAST +} AsInternetKind; + const gchar *as_relation_kind_to_string (AsRelationKind kind); AsRelationKind as_relation_kind_from_string (const gchar *kind_str); @@ -201,6 +224,9 @@ AsDisplaySideKind as_display_side_kind_from_string (const gchar *kind_str); const gchar *as_display_length_kind_to_string (AsDisplayLengthKind kind); AsDisplayLengthKind as_display_length_kind_from_string (const gchar *kind_str); +const gchar *as_internet_kind_to_string (AsInternetKind kind); +AsInternetKind as_internet_kind_from_string (const gchar *kind_str); + AsRelation *as_relation_new (void); AsRelationKind as_relation_get_kind (AsRelation *relation); @@ -242,6 +268,13 @@ AsDisplayLengthKind as_relation_get_value_display_length_kind (AsRelation *relat void as_relation_set_value_display_length_kind (AsRelation *relation, AsDisplayLengthKind kind); +AsInternetKind as_relation_get_value_internet_kind (AsRelation *relation); +void as_relation_set_value_internet_kind (AsRelation *relation, + AsInternetKind kind); +guint as_relation_get_value_internet_bandwidth (AsRelation *relation); +void as_relation_set_value_internet_bandwidth (AsRelation *relation, + guint bandwidth_mbitps); + gboolean as_relation_version_compare (AsRelation *relation, const gchar *version, GError **error); diff --git a/tests/test-xmldata.c b/tests/test-xmldata.c index dfac2829..6cbf4166 100644 --- a/tests/test-xmldata.c +++ b/tests/test-xmldata.c @@ -1423,15 +1423,18 @@ static const gchar *xmldata_relations = "\n" " Linux\n" " org.example.TestDependency\n" " small\n" + " always\n" " \n" " \n" " 2500\n" " usb:v1130p0202d*\n" " 4200\n" + " first-run\n" " \n" " \n" " gamepad\n" " keyboard\n" + " offline-only\n" " \n" "\n"; /** @@ -1455,9 +1458,9 @@ test_xml_read_relations (void) requires = as_component_get_requires (cpt); supports = as_component_get_supports (cpt); - g_assert_cmpint (requires->len, ==, 3); - g_assert_cmpint (recommends->len, ==, 3); - g_assert_cmpint (supports->len, ==, 2); + g_assert_cmpint (requires->len, ==, 4); + g_assert_cmpint (recommends->len, ==, 4); + g_assert_cmpint (supports->len, ==, 3); /* memory relation */ relation = AS_RELATION (g_ptr_array_index (recommends, 0)); @@ -1478,6 +1481,13 @@ test_xml_read_relations (void) g_assert_cmpint (as_relation_get_value_px (relation), ==, 4200); g_assert_cmpint (as_relation_get_compare (relation), ==, AS_RELATION_COMPARE_LE); + /* internet relation (REC) */ + relation = AS_RELATION (g_ptr_array_index (recommends, 3)); + g_assert_cmpint (as_relation_get_kind (relation), ==, AS_RELATION_KIND_RECOMMENDS); + g_assert_cmpint (as_relation_get_item_kind (relation), ==, AS_RELATION_ITEM_KIND_INTERNET); + g_assert_cmpint (as_relation_get_value_internet_kind (relation), ==, AS_INTERNET_KIND_FIRST_RUN); + g_assert_cmpint (as_relation_get_value_internet_bandwidth (relation), ==, 0); + /* kernel relation */ relation = AS_RELATION (g_ptr_array_index (requires, 0)); g_assert_cmpint (as_relation_get_kind (relation), ==, AS_RELATION_KIND_REQUIRES); @@ -1501,6 +1511,13 @@ test_xml_read_relations (void) g_assert_cmpint (as_relation_get_value_display_length_kind (relation), ==, AS_DISPLAY_LENGTH_KIND_SMALL); g_assert_cmpint (as_relation_get_compare (relation), ==, AS_RELATION_COMPARE_GE); + /* internet relation (REQ) */ + relation = AS_RELATION (g_ptr_array_index (requires, 3)); + g_assert_cmpint (as_relation_get_kind (relation), ==, AS_RELATION_KIND_REQUIRES); + g_assert_cmpint (as_relation_get_item_kind (relation), ==, AS_RELATION_ITEM_KIND_INTERNET); + g_assert_cmpint (as_relation_get_value_internet_kind (relation), ==, AS_INTERNET_KIND_ALWAYS); + g_assert_cmpint (as_relation_get_value_internet_bandwidth (relation), ==, 2); + /* control relation */ relation = AS_RELATION (g_ptr_array_index (supports, 0)); g_assert_cmpint (as_relation_get_kind (relation), ==, AS_RELATION_KIND_SUPPORTS); @@ -1510,6 +1527,13 @@ test_xml_read_relations (void) g_assert_cmpint (as_relation_get_kind (relation), ==, AS_RELATION_KIND_SUPPORTS); g_assert_cmpint (as_relation_get_item_kind (relation), ==, AS_RELATION_ITEM_KIND_CONTROL); g_assert_cmpint (as_relation_get_value_control_kind (relation), ==, AS_CONTROL_KIND_KEYBOARD); + + /* internet relation (supports) */ + relation = AS_RELATION (g_ptr_array_index (supports, 2)); + g_assert_cmpint (as_relation_get_kind (relation), ==, AS_RELATION_KIND_SUPPORTS); + g_assert_cmpint (as_relation_get_item_kind (relation), ==, AS_RELATION_ITEM_KIND_INTERNET); + g_assert_cmpint (as_relation_get_value_internet_kind (relation), ==, AS_INTERNET_KIND_OFFLINE_ONLY); + g_assert_cmpint (as_relation_get_value_internet_bandwidth (relation), ==, 0); } /** @@ -1530,6 +1554,9 @@ test_xml_write_relations (void) g_autoptr(AsRelation) dl_relation2 = NULL; g_autoptr(AsRelation) ctl_relation1 = NULL; g_autoptr(AsRelation) ctl_relation2 = NULL; + g_autoptr(AsRelation) internet_relation1 = NULL; + g_autoptr(AsRelation) internet_relation2 = NULL; + g_autoptr(AsRelation) internet_relation3 = NULL; cpt = as_component_new (); as_component_set_id (cpt, "org.example.RelationsTest"); @@ -1542,6 +1569,9 @@ test_xml_write_relations (void) dl_relation2 = as_relation_new (); ctl_relation1 = as_relation_new (); ctl_relation2 = as_relation_new (); + internet_relation1 = as_relation_new (); + internet_relation2 = as_relation_new (); + internet_relation3 = as_relation_new (); as_relation_set_kind (mem_relation, AS_RELATION_KIND_RECOMMENDS); as_relation_set_kind (moda_relation, AS_RELATION_KIND_RECOMMENDS); @@ -1551,6 +1581,9 @@ test_xml_write_relations (void) as_relation_set_kind (dl_relation2, AS_RELATION_KIND_REQUIRES); as_relation_set_kind (ctl_relation1, AS_RELATION_KIND_SUPPORTS); as_relation_set_kind (ctl_relation2, AS_RELATION_KIND_SUPPORTS); + as_relation_set_kind (internet_relation1, AS_RELATION_KIND_REQUIRES); + as_relation_set_kind (internet_relation2, AS_RELATION_KIND_RECOMMENDS); + as_relation_set_kind (internet_relation3, AS_RELATION_KIND_SUPPORTS); as_relation_set_item_kind (mem_relation, AS_RELATION_ITEM_KIND_MEMORY); as_relation_set_value_int (mem_relation, 2500); @@ -1576,6 +1609,16 @@ test_xml_write_relations (void) as_relation_set_value_display_length_kind (dl_relation2, AS_DISPLAY_LENGTH_KIND_SMALL); as_relation_set_compare (dl_relation2, AS_RELATION_COMPARE_GE); + as_relation_set_item_kind (internet_relation1, AS_RELATION_ITEM_KIND_INTERNET); + as_relation_set_value_internet_kind (internet_relation1, AS_INTERNET_KIND_ALWAYS); + as_relation_set_value_internet_bandwidth (internet_relation1, 2); + + as_relation_set_item_kind (internet_relation2, AS_RELATION_ITEM_KIND_INTERNET); + as_relation_set_value_internet_kind (internet_relation2, AS_INTERNET_KIND_FIRST_RUN); + + as_relation_set_item_kind (internet_relation3, AS_RELATION_ITEM_KIND_INTERNET); + as_relation_set_value_internet_kind (internet_relation3, AS_INTERNET_KIND_OFFLINE_ONLY); + as_relation_set_item_kind (ctl_relation1, AS_RELATION_ITEM_KIND_CONTROL); as_relation_set_item_kind (ctl_relation2, AS_RELATION_ITEM_KIND_CONTROL); as_relation_set_value_control_kind (ctl_relation1, AS_CONTROL_KIND_GAMEPAD); @@ -1589,6 +1632,9 @@ test_xml_write_relations (void) as_component_add_relation (cpt, dl_relation2); as_component_add_relation (cpt, ctl_relation1); as_component_add_relation (cpt, ctl_relation2); + as_component_add_relation (cpt, internet_relation1); + as_component_add_relation (cpt, internet_relation2); + as_component_add_relation (cpt, internet_relation3); res = as_xml_test_serialize (cpt, AS_FORMAT_STYLE_METAINFO); g_assert_true (as_xml_test_compare_xml (res, xmldata_relations)); diff --git a/tests/test-yamldata.c b/tests/test-yamldata.c index e3a1d3ed..a21459fa 100644 --- a/tests/test-yamldata.c +++ b/tests/test-yamldata.c @@ -1023,14 +1023,18 @@ static const gchar *yamldata_relations_field = "- id: org.example.TestDependency\n" " version: == 1.2\n" "- display_length: 4200\n" + "- internet: always\n" + " bandwidth_mbitps: 2\n" "Recommends:\n" "- memory: 2500\n" "- modalias: usb:v1130p0202d*\n" "- display_length: <= xlarge\n" " side: longest\n" + "- internet: first-run\n" "Supports:\n" "- control: gamepad\n" - "- control: keyboard\n"; + "- control: keyboard\n" + "- internet: offline-only\n"; /** * test_yaml_write_relations: @@ -1050,6 +1054,9 @@ test_yaml_write_relations (void) g_autoptr(AsRelation) dl_relation2 = NULL; g_autoptr(AsRelation) ctl_relation1 = NULL; g_autoptr(AsRelation) ctl_relation2 = NULL; + g_autoptr(AsRelation) internet_relation1 = NULL; + g_autoptr(AsRelation) internet_relation2 = NULL; + g_autoptr(AsRelation) internet_relation3 = NULL; cpt = as_component_new (); as_component_set_kind (cpt, AS_COMPONENT_KIND_GENERIC); @@ -1063,6 +1070,9 @@ test_yaml_write_relations (void) dl_relation2 = as_relation_new (); ctl_relation1 = as_relation_new (); ctl_relation2 = as_relation_new (); + internet_relation1 = as_relation_new (); + internet_relation2 = as_relation_new (); + internet_relation3 = as_relation_new (); as_relation_set_kind (mem_relation, AS_RELATION_KIND_RECOMMENDS); as_relation_set_kind (moda_relation, AS_RELATION_KIND_RECOMMENDS); @@ -1072,6 +1082,9 @@ test_yaml_write_relations (void) as_relation_set_kind (dl_relation2, AS_RELATION_KIND_REQUIRES); as_relation_set_kind (ctl_relation1, AS_RELATION_KIND_SUPPORTS); as_relation_set_kind (ctl_relation2, AS_RELATION_KIND_SUPPORTS); + as_relation_set_kind (internet_relation1, AS_RELATION_KIND_REQUIRES); + as_relation_set_kind (internet_relation2, AS_RELATION_KIND_RECOMMENDS); + as_relation_set_kind (internet_relation3, AS_RELATION_KIND_SUPPORTS); as_relation_set_item_kind (mem_relation, AS_RELATION_ITEM_KIND_MEMORY); as_relation_set_value_int (mem_relation, 2500); @@ -1097,6 +1110,16 @@ test_yaml_write_relations (void) as_relation_set_value_int (dl_relation2, 4200); as_relation_set_compare (dl_relation2, AS_RELATION_COMPARE_GE); + as_relation_set_item_kind (internet_relation1, AS_RELATION_ITEM_KIND_INTERNET); + as_relation_set_value_internet_kind (internet_relation1, AS_INTERNET_KIND_ALWAYS); + as_relation_set_value_internet_bandwidth (internet_relation1, 2); + + as_relation_set_item_kind (internet_relation2, AS_RELATION_ITEM_KIND_INTERNET); + as_relation_set_value_internet_kind (internet_relation2, AS_INTERNET_KIND_FIRST_RUN); + + as_relation_set_item_kind (internet_relation3, AS_RELATION_ITEM_KIND_INTERNET); + as_relation_set_value_internet_kind (internet_relation3, AS_INTERNET_KIND_OFFLINE_ONLY); + as_relation_set_item_kind (ctl_relation1, AS_RELATION_ITEM_KIND_CONTROL); as_relation_set_item_kind (ctl_relation2, AS_RELATION_ITEM_KIND_CONTROL); as_relation_set_value_control_kind (ctl_relation1, AS_CONTROL_KIND_GAMEPAD); @@ -1110,6 +1133,9 @@ test_yaml_write_relations (void) as_component_add_relation (cpt, dl_relation2); as_component_add_relation (cpt, ctl_relation1); as_component_add_relation (cpt, ctl_relation2); + as_component_add_relation (cpt, internet_relation1); + as_component_add_relation (cpt, internet_relation2); + as_component_add_relation (cpt, internet_relation3); /* test collection serialization */ res = as_yaml_test_serialize (cpt); @@ -1137,9 +1163,9 @@ test_yaml_read_relations (void) recommends = as_component_get_recommends (cpt); supports = as_component_get_supports (cpt); - g_assert_cmpint (requires->len, ==, 3); - g_assert_cmpint (recommends->len, ==, 3); - g_assert_cmpint (supports->len, ==, 2); + g_assert_cmpint (requires->len, ==, 4); + g_assert_cmpint (recommends->len, ==, 4); + g_assert_cmpint (supports->len, ==, 3); /* memory relation */ relation = AS_RELATION (g_ptr_array_index (recommends, 0)); @@ -1160,6 +1186,13 @@ test_yaml_read_relations (void) g_assert_cmpint (as_relation_get_value_display_length_kind (relation), ==, AS_DISPLAY_LENGTH_KIND_XLARGE); g_assert_cmpint (as_relation_get_compare (relation), ==, AS_RELATION_COMPARE_LE); + /* internet relation (REC) */ + relation = AS_RELATION (g_ptr_array_index (recommends, 3)); + g_assert_cmpint (as_relation_get_kind (relation), ==, AS_RELATION_KIND_RECOMMENDS); + g_assert_cmpint (as_relation_get_item_kind (relation), ==, AS_RELATION_ITEM_KIND_INTERNET); + g_assert_cmpint (as_relation_get_value_internet_kind (relation), ==, AS_INTERNET_KIND_FIRST_RUN); + g_assert_cmpint (as_relation_get_value_internet_bandwidth (relation), ==, 0); + /* kernel relation */ relation = AS_RELATION (g_ptr_array_index (requires, 0)); g_assert_cmpint (as_relation_get_kind (relation), ==, AS_RELATION_KIND_REQUIRES); @@ -1183,6 +1216,13 @@ test_yaml_read_relations (void) g_assert_cmpint (as_relation_get_value_px (relation), ==, 4200); g_assert_cmpint (as_relation_get_compare (relation), ==, AS_RELATION_COMPARE_GE); + /* internet relation (REQ) */ + relation = AS_RELATION (g_ptr_array_index (requires, 3)); + g_assert_cmpint (as_relation_get_kind (relation), ==, AS_RELATION_KIND_REQUIRES); + g_assert_cmpint (as_relation_get_item_kind (relation), ==, AS_RELATION_ITEM_KIND_INTERNET); + g_assert_cmpint (as_relation_get_value_internet_kind (relation), ==, AS_INTERNET_KIND_ALWAYS); + g_assert_cmpint (as_relation_get_value_internet_bandwidth (relation), ==, 2); + /* control relation */ relation = AS_RELATION (g_ptr_array_index (supports, 0)); g_assert_cmpint (as_relation_get_kind (relation), ==, AS_RELATION_KIND_SUPPORTS); @@ -1192,6 +1232,13 @@ test_yaml_read_relations (void) g_assert_cmpint (as_relation_get_kind (relation), ==, AS_RELATION_KIND_SUPPORTS); g_assert_cmpint (as_relation_get_item_kind (relation), ==, AS_RELATION_ITEM_KIND_CONTROL); g_assert_cmpint (as_relation_get_value_control_kind (relation), ==, AS_CONTROL_KIND_KEYBOARD); + + /* internet relation (supports) */ + relation = AS_RELATION (g_ptr_array_index (supports, 2)); + g_assert_cmpint (as_relation_get_kind (relation), ==, AS_RELATION_KIND_SUPPORTS); + g_assert_cmpint (as_relation_get_item_kind (relation), ==, AS_RELATION_ITEM_KIND_INTERNET); + g_assert_cmpint (as_relation_get_value_internet_kind (relation), ==, AS_INTERNET_KIND_OFFLINE_ONLY); + g_assert_cmpint (as_relation_get_value_internet_bandwidth (relation), ==, 0); }