#!/bin/bash

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

function BLKID()
{
  file=$1
  shift
  bzcat $FILES/blkid/$file.bz2 > temp.img
  # e2fsprogs' blkid outputs trailing spaces; no other blkid does.
  blkid "$@" temp.img | sed 's/ $//'
  rm temp.img
}

testing "cramfs" "BLKID cramfs" \
  'temp.img: LABEL="mycramfs" TYPE="cramfs"\n' "" ""
testing "ext2" "BLKID ext2" \
  'temp.img: LABEL="myext2" UUID="e59093ba-4135-4fdb-bcc4-f20beae4dfaf" TYPE="ext2"\n' \
  "" "" 
testing "ext3" "BLKID ext3" \
  'temp.img: LABEL="myext3" UUID="79d1c877-1a0f-4e7d-b21d-fc32ae3ef101" SEC_TYPE="ext2" TYPE="ext3"\n' \
  "" "" 
testing "ext4" "BLKID ext4" \
  'temp.img: LABEL="myext4" UUID="dc4b7c00-c0c0-4600-af7e-0335f09770fa" TYPE="ext4"\n' \
  "" ""
testing "f2fs" "BLKID f2fs" \
  'temp.img: LABEL="myf2fs" UUID="b53d3619-c204-4c0b-8504-36363578491c" TYPE="f2fs"\n' \
  "" ""
testing "iso" "BLKID iso" \
  'temp.img: LABEL="CDROM" UUID="2023-02-08-04-47-27-00" TYPE="iso9660"\n' \
  "" ""
testing "msdos" "BLKID msdos" \
  'temp.img: SEC_TYPE="msdos" LABEL="mymsdos" UUID="6E1E-0851" TYPE="vfat"\n' \
  "" ""

# We use -s here because toybox blkid can't do ntfs volume labels yet.
testing "ntfs" "BLKID ntfs -s UUID -s TYPE" \
  'temp.img: UUID="6EE1BF3808608585" TYPE="ntfs"\n' "" ""
testing "reiserfs" "BLKID reiser3" \
  'temp.img: LABEL="myreiser" UUID="a5b99bec-45cc-41d7-986e-32f4b6fc28f2" TYPE="reiserfs"\n' \
  "" ""
testing "squashfs" "BLKID squashfs" 'temp.img: TYPE="squashfs"\n' "" ""
testing "vfat" "BLKID vfat" \
  'temp.img: SEC_TYPE="msdos" LABEL="myvfat" UUID="7356-B91D" TYPE="vfat"\n' \
  "" ""
testing "fat32" "BLKID fat32" \
  'temp.img: LABEL="myfat32" UUID="2E7D-E046" TYPE="vfat"\n' \
  "" ""
testing "xfs" "BLKID xfs" \
  'temp.img: LABEL="XFS_test" UUID="d63a1dc3-27d5-4dd4-8b38-f4f97f495c6f" TYPE="xfs"\n' \
  "" ""

# Unlike util-linux's blkid, toybox blkid can read from stdin.
toyonly testing "stdin" "bzcat $FILES/blkid/squashfs.bz2 | blkid -" \
  '-: TYPE="squashfs"\n' "" ""

#testing "minix" 'bzcat "$BDIR"/minix.bz2 | blkid -'
#adfs bfs btrfs cramfs jfs nilfs romfs
#vfat  // fat32 fat12 fat16

bzcat $FILES/blkid/ext3.bz2 > temp.img
testcmd "-o value -s" "-o value -s TYPE temp.img" 'ext3\n' "" ""
testcmd "-o export" "-o export temp.img" 'DEVNAME=temp.img\nLABEL=myext3\nUUID=79d1c877-1a0f-4e7d-b21d-fc32ae3ef101\nSEC_TYPE=ext2\nTYPE=ext3\n' "" ""
rm temp.img
