Home | History | Annotate | Line # | Download | only in games
t_morse.sh revision 1.1
      1  1.1  rillig #	$NetBSD: t_morse.sh,v 1.1 2024/06/16 18:40:58 rillig Exp $
      2  1.1  rillig #
      3  1.1  rillig # Copyright (c) 2024 The NetBSD Foundation, Inc.
      4  1.1  rillig # All rights reserved.
      5  1.1  rillig #
      6  1.1  rillig # Redistribution and use in source and binary forms, with or without
      7  1.1  rillig # modification, are permitted provided that the following conditions
      8  1.1  rillig # are met:
      9  1.1  rillig # 1. Redistributions of source code must retain the above copyright
     10  1.1  rillig #    notice, this list of conditions and the following disclaimer.
     11  1.1  rillig # 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  rillig #    notice, this list of conditions and the following disclaimer in the
     13  1.1  rillig #    documentation and/or other materials provided with the distribution.
     14  1.1  rillig #
     15  1.1  rillig # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16  1.1  rillig # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17  1.1  rillig # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  1.1  rillig # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19  1.1  rillig # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  1.1  rillig # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  1.1  rillig # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  1.1  rillig # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  1.1  rillig # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  1.1  rillig # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.1  rillig # POSSIBILITY OF SUCH DAMAGE.
     26  1.1  rillig #
     27  1.1  rillig 
     28  1.1  rillig atf_test_case digits
     29  1.1  rillig digits_body() {
     30  1.1  rillig 	trailing_space=' '
     31  1.1  rillig 	morse_s_digits="\
     32  1.1  rillig  -----
     33  1.1  rillig  .----
     34  1.1  rillig  ..---
     35  1.1  rillig  ...--
     36  1.1  rillig  ....-
     37  1.1  rillig  .....
     38  1.1  rillig  -....
     39  1.1  rillig  --...
     40  1.1  rillig  ---..
     41  1.1  rillig  ----.
     42  1.1  rillig $trailing_space
     43  1.1  rillig  ...-.-
     44  1.1  rillig "
     45  1.1  rillig 	atf_check -o "inline:$morse_s_digits" \
     46  1.1  rillig 	    /usr/games/morse -s 0123456789
     47  1.1  rillig 
     48  1.1  rillig 	morse_digits="\
     49  1.1  rillig  daw daw daw daw daw
     50  1.1  rillig  dit daw daw daw daw
     51  1.1  rillig  dit dit daw daw daw
     52  1.1  rillig  dit dit dit daw daw
     53  1.1  rillig  dit dit dit dit daw
     54  1.1  rillig  dit dit dit dit dit
     55  1.1  rillig  daw dit dit dit dit
     56  1.1  rillig  daw daw dit dit dit
     57  1.1  rillig  daw daw daw dit dit
     58  1.1  rillig  daw daw daw daw dit
     59  1.1  rillig 
     60  1.1  rillig  dit dit dit daw dit daw
     61  1.1  rillig "
     62  1.1  rillig 	atf_check -o "inline:$morse_digits" \
     63  1.1  rillig 	    /usr/games/morse 0123456789
     64  1.1  rillig }
     65  1.1  rillig 
     66  1.1  rillig # Before 2024-06-16, non-ASCII characters invoked undefined behavior,
     67  1.1  rillig # possibly crashing morse.
     68  1.1  rillig atf_test_case nonascii
     69  1.1  rillig nonascii_body()
     70  1.1  rillig {
     71  1.1  rillig 	expected="\
     72  1.1  rillig 
     73  1.1  rillig  dit dit dit daw dit daw
     74  1.1  rillig "
     75  1.1  rillig 	atf_check -o "inline:$expected" \
     76  1.1  rillig 	    /usr/games/morse 
     77  1.1  rillig }
     78  1.1  rillig 
     79  1.1  rillig atf_init_test_cases()
     80  1.1  rillig {
     81  1.1  rillig 	atf_add_test_case digits
     82  1.1  rillig 	atf_add_test_case nonascii
     83  1.1  rillig }
     84