1 #
   2 # This file and its contents are supplied under the terms of the
   3 # Common Development and Distribution License ("CDDL"), version 1.0.
   4 # You may only use this file in accordance with the terms of version
   5 # 1.0 of the CDDL.
   6 #
   7 # A full copy of the text of the CDDL should have accompanied this
   8 # source.  A copy of the CDDL is also available via the Internet at
   9 # http://www.illumos.org/license/CDDL.
  10 #
  11 
  12 #
  13 # Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  14 #
  15 
  16 #
  17 # Copyright (c) 2016 by Delphix. All rights reserved.
  18 #
  19 
  20 . $STF_SUITE/include/libtest.shlib
  21 . $STF_SUITE/tests/functional/casenorm/casenorm.cfg
  22 
  23 function create_testfs
  24 {
  25         typeset opts=$1
  26 
  27         rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR
  28         mkdir -p $TESTDIR || log_unresolved Could not create $TESTDIR
  29 
  30         log_must zfs create $opts $TESTPOOL/$TESTFS
  31         log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
  32 }
  33 
  34 function destroy_testfs
  35 {
  36         if datasetexists $TESTPOOL/$TESTFS ; then
  37                 log_must zfs destroy -f $TESTPOOL/$TESTFS
  38                 rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR
  39         fi
  40 }
  41 
  42 function create_file
  43 {
  44         typeset name=$TESTDIR/$1
  45 
  46         echo $name > $name
  47 }
  48 
  49 function delete_file
  50 {
  51         typeset name=$TESTDIR/$1
  52 
  53         rm $name >/dev/null 2>&1
  54 
  55         if [[ $? -ne 0 ]] ; then
  56                 return 1
  57         fi
  58 
  59         if [[ -f $name ]] ; then
  60                 return 2
  61         fi
  62 }
  63 
  64 function lookup_file
  65 {
  66         typeset name=$1
  67 
  68         zlook -l $TESTDIR $name >/dev/null 2>&1
  69 }
  70 
  71 function lookup_file_ci
  72 {
  73         typeset name=$1
  74 
  75         zlook -il $TESTDIR $name >/dev/null 2>&1
  76 }
  77 
  78 function lookup_any
  79 {
  80         for name in $NAMES_ALL ; do
  81                 lookup_file $name
  82                 if [[ $? -eq 0 ]] ; then
  83                         return 0
  84                 fi
  85         done
  86 
  87         return 1
  88 }
  89 
  90 function switch_norm
  91 {
  92         typeset norm=$(get_norm $1)
  93 
  94         if [[ $norm == "C" ]] ; then
  95                 print "D"
  96         else
  97                 print "C"
  98         fi
  99 }
 100 
 101 function get_norm
 102 {
 103         if [[ "${NAMES_C#*$1}" != "${NAMES_C}" ]] ; then
 104                 print "C"
 105         elif [[ "${NAMES_D#*$1}" != "${NAMES_D}" ]] ; then
 106                 print "D"
 107         else
 108                 return 1
 109         fi
 110 }
 111 
 112 function get_case
 113 {
 114         if [[ ${NAMES_UPPER#*$1} != ${NAMES_UPPER} ]] ; then
 115                 print "UPPER"
 116         elif [[ ${NAMES_LOWER#*$1} != ${NAMES_LOWER} ]] ; then
 117                 print "LOWER"
 118         elif [[ ${NAMES_ORIG#*$1} != ${NAMES_ORIG} ]] ; then
 119                 print "ORIG"
 120         else
 121                 return 1
 122         fi
 123 }