diff --git a/docs/xml/metainfo-component.xml b/docs/xml/metainfo-component.xml
index 35c0a5d9c..654163df5 100644
--- a/docs/xml/metainfo-component.xml
+++ b/docs/xml/metainfo-component.xml
@@ -1106,6 +1106,71 @@
+
+ <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 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
+
+
+
+
+ first-run
+
+
+ always
+]]>
+ Valid for: requires, recommends, supports
+
+
+
diff --git a/src/as-relation.c b/src/as-relation.c
index 1a6a50af1..270574487 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,15 @@ as_relation_load_from_xml (AsRelation *relation, AsContext *ctx, xmlNode *node,
g_autofree gchar *side_str = as_xml_get_prop_value (node, "side");
priv->display_side_kind = as_display_side_kind_from_string (side_str);
+ g_free (g_steal_pointer (&priv->version));
+ } else if (priv->item_kind == AS_RELATION_ITEM_KIND_INTERNET) {
+ g_autofree gchar *bandwidth_str = as_xml_get_prop_value (node, "bandwidth_mbitps");
+
+ if (bandwidth_str != NULL)
+ priv->bandwidth_mbitps = g_ascii_strtoll (bandwidth_str, NULL, 10);
+ else
+ priv->bandwidth_mbitps = 0;
+
g_free (g_steal_pointer (&priv->version));
} else if (priv->item_kind != AS_RELATION_ITEM_KIND_CONTROL) {
g_free (priv->version);
@@ -1100,6 +1249,11 @@ as_relation_to_xml_node (AsRelation *relation, AsContext *ctx, xmlNode *root)
as_relation_item_kind_to_string (priv->item_kind),
as_control_kind_to_string (as_relation_get_value_control_kind (relation)));
+ } else if (priv->item_kind == AS_RELATION_ITEM_KIND_INTERNET) {
+ n = as_xml_add_text_node (root,
+ as_relation_item_kind_to_string (priv->item_kind),
+ as_internet_kind_to_string (as_relation_get_value_internet_kind (relation)));
+
} else {
n = as_xml_add_text_node (root,
as_relation_item_kind_to_string (priv->item_kind),
@@ -1114,6 +1268,13 @@ as_relation_to_xml_node (AsRelation *relation, AsContext *ctx, xmlNode *root)
as_xml_add_text_prop (n, "compare",
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) {
as_xml_add_text_prop (n,
@@ -1160,6 +1321,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) {
@@ -1203,6 +1366,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));
}
@@ -1267,6 +1434,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 bfac725c2..d7110b27f 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 215d97f4f..ca81df0af 100644
--- a/tests/test-xmldata.c
+++ b/tests/test-xmldata.c
@@ -1426,15 +1426,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";
/**
@@ -1458,9 +1461,13 @@ 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);
+
+ /* component replacement */
+ g_assert_cmpint (as_component_get_replaces (cpt)->len, ==, 1);
+ g_assert_cmpstr (g_ptr_array_index (as_component_get_replaces (cpt), 0), ==, "org.example.old_test");
/* memory relation */
relation = AS_RELATION (g_ptr_array_index (recommends, 0));
@@ -1481,6 +1488,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);
@@ -1504,6 +1518,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);
@@ -1514,9 +1535,12 @@ test_xml_read_relations (void)
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);
- /* component replacement */
- g_assert_cmpint (as_component_get_replaces (cpt)->len, ==, 1);
- g_assert_cmpstr (g_ptr_array_index (as_component_get_replaces (cpt), 0), ==, "org.example.old_test");
+ /* 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);
}
/**
@@ -1537,6 +1561,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");
@@ -1549,6 +1576,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);
@@ -1558,6 +1588,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);
@@ -1583,6 +1616,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);
@@ -1596,6 +1639,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);
as_component_add_replaces (cpt, "org.example.old_test");
diff --git a/tests/test-yamldata.c b/tests/test-yamldata.c
index 6abe2e202..c02239059 100644
--- a/tests/test-yamldata.c
+++ b/tests/test-yamldata.c
@@ -1025,14 +1025,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:
@@ -1052,6 +1056,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);
@@ -1065,6 +1072,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);
@@ -1074,6 +1084,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);
@@ -1099,6 +1112,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);
@@ -1112,6 +1135,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);
as_component_add_replaces (cpt, "org.example.old_test");
@@ -1141,9 +1167,13 @@ 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);
+
+ /* component replacement */
+ g_assert_cmpint (as_component_get_replaces (cpt)->len, ==, 1);
+ g_assert_cmpstr (g_ptr_array_index (as_component_get_replaces (cpt), 0), ==, "org.example.old_test");
/* memory relation */
relation = AS_RELATION (g_ptr_array_index (recommends, 0));
@@ -1164,6 +1194,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);
@@ -1187,6 +1224,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);
@@ -1197,9 +1241,12 @@ test_yaml_read_relations (void)
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);
- /* component replacement */
- g_assert_cmpint (as_component_get_replaces (cpt)->len, ==, 1);
- g_assert_cmpstr (g_ptr_array_index (as_component_get_replaces (cpt), 0), ==, "org.example.old_test");
+ /* 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);
}