@@ -522,6 +522,90 @@ static void test_testcases_teardown(void)
522522 at_params_list_free (& test_list2 );
523523}
524524
525+ static void test_at_cmd_setup (void )
526+ {
527+ at_params_list_init (& test_list2 , TEST_PARAMS2 );
528+ }
529+
530+ static void test_at_cmd (void )
531+ {
532+ int ret ;
533+ char tmpbuf [32 ];
534+ u32_t tmpbuf_len ;
535+ u16_t tmpshrt ;
536+
537+ static const char at_cmd_cclk [] = "AT+CCLK=\"18/12/06,22:10:00+08\"" ;
538+
539+ ret = at_parser_params_from_str (at_cmd_cclk , NULL , & test_list2 );
540+ zassert_true (ret == 0 , "at_parser_params_from_str should return 0" );
541+
542+ ret = at_params_valid_count_get (& test_list2 );
543+ zassert_true (ret == 2 ,
544+ "at_params_valid_count_get returns wrong valid count" );
545+
546+ zassert_true (at_params_type_get (& test_list2 , 0 ) == AT_PARAM_TYPE_STRING ,
547+ "Param type at index 0 should be a string" );
548+ zassert_true (at_params_type_get (& test_list2 , 1 ) == AT_PARAM_TYPE_STRING ,
549+ "Param type at index 1 should be a string" );
550+
551+ tmpbuf_len = sizeof (tmpbuf );
552+ zassert_equal (0 , at_params_string_get (& test_list2 , 0 ,
553+ tmpbuf , & tmpbuf_len ),
554+ "Get string should not fail" );
555+ zassert_equal (0 , memcmp ("AT+CCLK" , tmpbuf , tmpbuf_len ),
556+ "The string in tmpbuf should equal to AT+CCLK" );
557+
558+ tmpbuf_len = sizeof (tmpbuf );
559+ zassert_equal (0 , at_params_string_get (& test_list2 , 1 ,
560+ tmpbuf , & tmpbuf_len ),
561+ "Get string should not fail" );
562+ zassert_equal (0 , memcmp ("18/12/06,22:10:00+08" , tmpbuf , tmpbuf_len ),
563+ "The string in tmpbuf should equal to "
564+ "18/12/06,22:10:00+08" );
565+
566+ static const char at_cmd_xsystemmode [] = "AT%XSYSTEMMODE=1,2,3,4" ;
567+
568+ ret = at_parser_params_from_str (at_cmd_xsystemmode , NULL , & test_list2 );
569+ zassert_true (ret == 0 , "at_parser_params_from_str should return 0" );
570+
571+ ret = at_params_valid_count_get (& test_list2 );
572+ zassert_true (ret == 5 ,
573+ "at_params_valid_count_get returns wrong valid count" );
574+
575+ zassert_true (at_params_type_get (& test_list2 , 0 ) == AT_PARAM_TYPE_STRING ,
576+ "Param type at index 0 should be a string" );
577+ zassert_true (at_params_type_get (& test_list2 , 1 ) ==
578+ AT_PARAM_TYPE_NUM_SHORT ,
579+ "Param type at index 1 should be a string" );
580+ zassert_true (at_params_type_get (& test_list2 , 2 ) ==
581+ AT_PARAM_TYPE_NUM_SHORT ,
582+ "Param type at index 2 should be a string" );
583+ zassert_true (at_params_type_get (& test_list2 , 3 ) ==
584+ AT_PARAM_TYPE_NUM_SHORT ,
585+ "Param type at index 3 should be a string" );
586+ zassert_true (at_params_type_get (& test_list2 , 4 ) ==
587+ AT_PARAM_TYPE_NUM_SHORT ,
588+ "Param type at index 4 should be a string" );
589+
590+ zassert_equal (0 , at_params_short_get (& test_list2 , 1 , & tmpshrt ),
591+ "Get short should not fail" );
592+ zassert_equal (1 , tmpshrt , "Short should be 1" );
593+ zassert_equal (0 , at_params_short_get (& test_list2 , 2 , & tmpshrt ),
594+ "Get short should not fail" );
595+ zassert_equal (2 , tmpshrt , "Short should be 2" );
596+ zassert_equal (0 , at_params_short_get (& test_list2 , 3 , & tmpshrt ),
597+ "Get short should not fail" );
598+ zassert_equal (3 , tmpshrt , "Short should be 3" );
599+ zassert_equal (0 , at_params_short_get (& test_list2 , 4 , & tmpshrt ),
600+ "Get short should not fail" );
601+ zassert_equal (4 , tmpshrt , "Short should be 4" );
602+ }
603+
604+ static void test_at_cmd_teardown (void )
605+ {
606+ at_params_list_free (& test_list2 );
607+ }
608+
525609void test_main (void )
526610{
527611 ztest_test_suite (at_cmd_parser ,
@@ -540,7 +624,11 @@ void test_main(void)
540624 ztest_unit_test_setup_teardown (
541625 test_testcases ,
542626 test_testcases_setup ,
543- test_testcases_teardown )
627+ test_testcases_teardown ),
628+ ztest_unit_test_setup_teardown (
629+ test_at_cmd ,
630+ test_at_cmd_setup ,
631+ test_at_cmd_teardown )
544632 );
545633
546634 ztest_run_test_suite (at_cmd_parser );
0 commit comments