From 9b71be04ea600189e390bb111624ad5c2d248a4c Mon Sep 17 00:00:00 2001
From: Frederic Marec <frederic.marec@iot.bzh>
Date: Wed, 16 Jan 2019 17:07:21 +0100
Subject: Improve tests for 4a-alsa-core

Change-Id: Ief879bd4856b3aa906c3b256c432e2a5ddf78fcd
Signed-off-by: Frederic Marec <frederic.marec@iot.bzh>
---
 test/CMakeLists.txt                           |   9 +-
 test/afb-test/etc/aft-4a-alsacore-config.json |   2 +-
 test/afb-test/tests/alsacore_APITest.lua      | 150 ++++++++++++++++++++++++++
 test/afb-test/tests/alsacore_BasicAPITest.lua |   6 +-
 4 files changed, 160 insertions(+), 7 deletions(-)
 create mode 100644 test/afb-test/tests/alsacore_APITest.lua

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 9df744e..fb9abf5 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,5 +1,5 @@
 ###########################################################################
-# Copyright 2018 IoT.bzh
+# Copyright 2015 - 2019 IoT.bzh
 #
 # author:Frédéric Marec <frederic.marec@iot.bzh>
 #
@@ -19,4 +19,9 @@
 
 # Include any directory not starting with _
 # -----------------------------------------------------
-PROJECT_SUBDIRS_ADD(${PROJECT_SRC_DIR_PATTERN})
\ No newline at end of file
+PROJECT_SUBDIRS_ADD(${PROJECT_SRC_DIR_PATTERN})
+
+ADD_TEST(NAME AGL_4A_ALSA_CORE
+	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+	COMMAND afm-test ${CMAKE_BINARY_DIR}/package ${CMAKE_BINARY_DIR}/package-test
+)
\ No newline at end of file
diff --git a/test/afb-test/etc/aft-4a-alsacore-config.json b/test/afb-test/etc/aft-4a-alsacore-config.json
index 32de328..d582082 100644
--- a/test/afb-test/etc/aft-4a-alsacore-config.json
+++ b/test/afb-test/etc/aft-4a-alsacore-config.json
@@ -16,7 +16,7 @@
         "action": "lua://AFT#_launch_test",
         "args": {
             "trace": "alsacore",
-            "files": ["alsacore_BasicAPITest.lua"]
+            "files": ["alsacore_BasicAPITest.lua", "alsacore_APITest.lua"]
         }
     }
 }
\ No newline at end of file
diff --git a/test/afb-test/tests/alsacore_APITest.lua b/test/afb-test/tests/alsacore_APITest.lua
new file mode 100644
index 0000000..d3401f3
--- /dev/null
+++ b/test/afb-test/tests/alsacore_APITest.lua
@@ -0,0 +1,150 @@
+--[[
+   Copyright (C) 2019 "IoT.bzh"
+   Author Frédéric Marec <frederic.marec@iot.bzh>
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+
+   NOTE: strict mode: every global variables should be prefixed by '_'
+--]]
+
+local testPrefix ="alsacore_APITest_"
+local devid_keys = {"devid", "wrong_key", nil}
+local devid_values = {"hw:0", "wrong_value", 3.141592654, -275, nil}
+local sndname_keys = {"sndname", "wrong_key", nil}
+local sndname_values = {"HDA-Intel", "wrong_value", 3.141592654, -275, nil}
+local prefix_keys = {"prefix", "wrong_key", nil}
+local prefix_values = {"4a-hal-generic", "wrong_value", 3.141592654, -275, nil}
+local name_keys = { "name", "wrong_key", nil}
+local name_values = {"hal-4a-intel", "wrong_value", 3.141592654, -275, nil}
+local value_keys = { "value", "wrong_key", nil}
+local value_values = {10, "wrong_value", 3.141592654, -275, nil}
+local ctl_keys = { "ctl", "wrong_key", nil}
+local mode_keys = { "mode", "wrong_key", nil}
+local mode_values = {3, "wrong_value", 3.141592654, -275, nil}
+
+local function formatize (arg)
+  return tostring(arg):gsub("[^a-zA-Z0-9_]", "_")
+end
+
+for _, devid_key in pairs(devid_keys)
+do
+  for _, devid_value in pairs(devid_values)
+  do
+    local arg1 = formatize(devid_key).."_"
+    local arg2 = formatize(devid_value).."_"
+
+    -- This tests the 'ping' verb of the alsacore API
+    _AFT.testVerbStatusSuccess(testPrefix.."ping", "alsacore","ping", {}, nil, nil)
+
+    -- This tests the 'infoget' verb of the alsacore API
+    _AFT.testVerbStatusSuccess(testPrefix.."infoget", "alsacore","infoget", {}, nil, nil)
+
+    -- This tests the 'ctlget' verb of the alsacore API
+    _AFT.testVerbStatusSuccess(testPrefix.."ctlget", "alsacore","ctlget", {devid = "hw:0"}, nil, nil)
+    _AFT.testVerbStatusError(testPrefix.."ctlget", "alsacore","ctlget", {}, nil, nil)
+
+    -- This tests the 'ctlset' verb of the alsacore API
+    _AFT.testVerbStatusSuccess(testPrefix.."ctlset", "alsacore","ctlset", {devid = "hw:0"}, nil, nil)
+    _AFT.testVerbStatusError(testPrefix.."ctlset", "alsacore","ctlset", {}, nil, nil)
+
+    -- This tests the 'subscribe' verb of the alsacore API
+    _AFT.testVerbStatusSuccess(testPrefix.."subscribe", "alsacore","subscribe", {devid = "hw:0"}, nil, nil)
+    _AFT.testVerbStatusError(testPrefix.."subscribe", "alsacore","subscribe", {}, nil, nil)
+
+    for _, sndname_key in pairs(sndname_keys)
+    do
+      for _, sndname_value in pairs(sndname_values)
+      do
+        local arg3 = formatize(sndname_key).."_"
+        local arg4 = formatize(sndname_value).."_"
+
+        -- This tests the 'cardidget' verb of the alsacore API
+        _AFT.testVerbStatusSuccess(testPrefix.."cardidget", "alsacore","cardidget", {devid = "hw:0", sndname="HDA-Intel"}, nil, nil)
+        _AFT.testVerbStatusSuccess(testPrefix.."cardidget", "alsacore","cardidget", {sndname="HDA-Intel"}, nil, nil)
+        _AFT.testVerbStatusError(testPrefix.."cardidget", "alsacore","cardidget", {devid = "hw:0"}, nil, nil)
+
+        for _, name_key in pairs(name_keys)
+        do
+          for _, name_value in pairs(name_values)
+          do
+            for _, prefix_key in pairs(prefix_keys)
+            do
+              for _, prefix_value in pairs(prefix_values)
+              do
+                for _, value_key in pairs(value_keys)
+                do
+                  for _, value_value in pairs(value_values)
+                  do
+
+                    local arg5 = formatize(name_key).."_"
+                    local arg6 = formatize(name_value).."_"
+                    local arg7 = formatize(prefix_key).."_"
+                    local arg8 = formatize(prefix_value).."_"
+                    local arg9 = formatize(value_key).."_"
+                    local arg10 = formatize(value_value).."_"
+
+                    -- This tests the 'halregister' verb of the alsacore API
+                    _AFT.testVerbStatusSuccess(testPrefix.."halregister", "alsacore","halregister", {devid = "hw:0", prefix = "4a-hal-generic", name = "hal-4a-intel", value = 10, sndname="HDA-Intel"}, nil, nil)
+                    _AFT.testVerbStatusSuccess(testPrefix.."halregister", "alsacore","halregister", {prefix = "4a-hal-generic", name = "hal-4a-intel", value = 10, sndname="HDA-Intel"}, nil, nil)
+                    _AFT.testVerbStatusError(testPrefix.."halregister", "alsacore","halregister", {devid = "hw:0", prefix = "4a-hal-generic", name = "hal-4a-intel", value = 10}, nil, nil)
+                    _AFT.testVerbStatusError(testPrefix.."halregister", "alsacore","halregister", {devid = "hw:0", name = "hal-4a-intel", value = 10, sndname="HDA-Intel"}, nil, nil)
+
+                    -- This tests the 'hallist' verb of the alsacore API
+                    _AFT.testVerbStatusSuccess(testPrefix.."hallist", "alsacore","hallist", {devid = "hw:0"}, nil, nil)
+                    _AFT.testVerbStatusSuccess(testPrefix.."hallist", "alsacore","hallist", {}, nil, nil)
+
+                    -- This tests the 'pcminfo' verb of the alsacore API
+                    _AFT.testVerbStatusError(testPrefix.."pcminfo", "alsacore","pcminfo", {devid = "hw:0", name = "sysdefault:CARD=PCH"}, nil, nil)
+                    _AFT.testVerbStatusError(testPrefix.."pcminfo", "alsacore","pcminfo", {name = "sysdefault:CARD=PCH"}, nil, nil)
+
+                    -- This tests the 'ucmquery' verb of the alsacore API
+                    _AFT.testVerbStatusError(testPrefix.."ucmquery", "alsacore","ucmquery", {devid = "hw:0", name = "sysdefault"}, nil, nil)
+
+                    -- This tests the 'ucmset' verb of the alsacore API
+                    _AFT.testVerbStatusError(testPrefix.."ucmset", "alsacore","ucmset", {devid = "hw:0", name = "sysdefault"}, nil, nil)
+
+                    -- This tests the 'ucmget' verb of the alsacore API
+                    _AFT.testVerbStatusError(testPrefix.."ucmget", "alsacore","ucmget", {devid = "hw:0", name = "sysdefault"}, nil, nil)
+
+                    -- This tests the 'ucmreset' verb of the alsacore API
+                    _AFT.testVerbStatusError(testPrefix.."ucmreset", "alsacore","ucmreset", {devid = "hw:0", name = "sysdefault"}, nil, nil)
+
+                    -- This tests the 'ucmclose' verb of the alsacore API
+                    _AFT.testVerbStatusError(testPrefix.."ucmclose", "alsacore","ucmclose", {devid = "hw:0", name = "sysdefault"}, nil, nil)
+                  end
+                end
+              end
+            end
+          end
+        end
+      end
+    end
+  end
+  for _, ctl_key in pairs(ctl_keys)
+  do
+    for _, mode_key in pairs(mode_keys)
+    do
+      for _, mode_key in pairs(mode_values)
+      do
+        local arg5 = formatize(ctl_key).."_"
+        local arg7 = formatize(mode_key).."_"
+        local arg8 = formatize(mode_value).."_"
+
+        -- This tests the 'addcustomctl' verb of the alsacore API
+        _AFT.testVerbStatusError(testPrefix.."addcustomctl", "alsacore","addcustomctl", {devid = "hw:0", ctl = "test-addcustomctl", mode = 3}, nil, nil)
+
+      end
+    end
+  end
+end
\ No newline at end of file
diff --git a/test/afb-test/tests/alsacore_BasicAPITest.lua b/test/afb-test/tests/alsacore_BasicAPITest.lua
index be8e1a7..835208b 100644
--- a/test/afb-test/tests/alsacore_BasicAPITest.lua
+++ b/test/afb-test/tests/alsacore_BasicAPITest.lua
@@ -1,5 +1,5 @@
 --[[
-   Copyright (C) 2018 "IoT.bzh"
+   Copyright (C) 2018 - 2019 "IoT.bzh"
    Author Frédéric Marec <frederic.marec@iot.bzh>
 
    Licensed under the Apache License, Version 2.0 (the "License");
@@ -73,6 +73,4 @@ _AFT.testVerbStatusError(testPrefix.."ucmreset", "alsacore","ucmreset", {devid =
 _AFT.testVerbStatusError(testPrefix.."ucmclose", "alsacore","ucmclose", {devid = "hw:0", name = "sysdefault"}, nil, nil)
 
 -- This tests the 'addcustomctl' verb of the alsacore API
-_AFT.testVerbStatusError(testPrefix.."addcustomctl", "alsacore","addcustomctl", {devid = "hw:0", ctl = "test-addcustomctl", mode = 3}, nil, nil)
-
-_AFT.exitAtEnd()
\ No newline at end of file
+_AFT.testVerbStatusError(testPrefix.."addcustomctl", "alsacore","addcustomctl", {devid = "hw:0", ctl = "test-addcustomctl", mode = 3}, nil, nil)
\ No newline at end of file
-- 
cgit