]> git.alsa-project.org Git - alsa-lib.git/commitdiff
test: add a test for list operation to user-defined element sets
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 24 May 2017 14:34:14 +0000 (23:34 +0900)
committerTakashi Iwai <tiwai@suse.de>
Thu, 25 May 2017 16:45:41 +0000 (18:45 +0200)
Current implementation of test for user-defined element doesn't perform
list operation. This commit adds easy test for the operation.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
test/user-ctl-element-set.c

index 75083d219fe6725870ad73ccf8aa758eb66e6d7d..8635c156195b1da4e27efecd7c705403a5de4e53 100644 (file)
@@ -433,6 +433,78 @@ static int check_event(struct elem_set_trial *trial, unsigned int mask,
        return 0;
 }
 
+static int check_elem_list(struct elem_set_trial *trial)
+{
+       snd_ctl_elem_list_t *list;
+       snd_ctl_elem_id_t *id;
+       int e;
+       unsigned int i;
+       int err;
+
+       snd_ctl_elem_list_alloca(&list);
+       snd_ctl_elem_id_alloca(&id);
+
+       err = snd_ctl_elem_list(trial->handle, list);
+       if (err < 0)
+               return err;
+
+       /* Certainly some elements are already added. */
+       if (snd_ctl_elem_list_get_count(list) == 0)
+               return -EIO;
+
+       err = snd_ctl_elem_list_alloc_space(list,
+                                           snd_ctl_elem_list_get_count(list));
+       if (err < 0)
+               return err;
+
+       err = snd_ctl_elem_list(trial->handle, list);
+       if (err < 0)
+               goto end;
+
+       if (trial->element_count > snd_ctl_elem_list_get_count(list)) {
+               err = -EIO;
+               goto end;
+       }
+
+       i = 0;
+       for (e = 0; e < snd_ctl_elem_list_get_count(list); ++e) {
+               snd_ctl_elem_list_get_id(list, e, id);
+
+               if (strcmp(snd_ctl_elem_id_get_name(id),
+                          snd_ctl_elem_id_get_name(trial->id)) != 0)
+                       continue;
+               if (snd_ctl_elem_id_get_interface(id) !=
+                   snd_ctl_elem_id_get_interface(trial->id))
+                       continue;
+               if (snd_ctl_elem_id_get_device(id) !=
+                   snd_ctl_elem_id_get_device(trial->id))
+                       continue;
+               if (snd_ctl_elem_id_get_subdevice(id) !=
+                   snd_ctl_elem_id_get_subdevice(trial->id))
+                       continue;
+
+               /*
+                * Here, I expect the list includes element ID data in numerical
+                * order. Actually, it does.
+                */
+               if (snd_ctl_elem_id_get_numid(id) !=
+                   snd_ctl_elem_id_get_numid(trial->id) + i)
+                       continue;
+               if (snd_ctl_elem_id_get_index(id) !=
+                   snd_ctl_elem_id_get_index(trial->id) + i)
+                       continue;
+
+               ++i;
+       }
+
+       if (i != trial->element_count)
+               err = -EIO;
+end:
+       snd_ctl_elem_list_free_space(list);
+
+       return err;
+}
+
 static int check_elem_set_props(struct elem_set_trial *trial)
 {
        snd_ctl_elem_id_t *id;
@@ -701,6 +773,14 @@ int main(void)
                        break;
                }
 
+               /* Check added elements are retrieved in a list. */
+               err = check_elem_list(&trial);
+               if (err < 0) {
+                       printf("Fail to list each element with %s type.\n",
+                              snd_ctl_elem_type_name(trial.type));
+                       break;
+               }
+
                /* Check properties of each element in this element set. */
                err = check_elem_set_props(&trial);
                if (err < 0) {