@@ -610,4 +610,45 @@ mod tests {
610
610
assert_eq ! ( components[ 1 ] . critical( ) , Some ( 0.2 ) ) ;
611
611
assert_eq ! ( components[ 1 ] . id( ) , Some ( "hwmon0_2" ) ) ;
612
612
}
613
+
614
+ #[ test]
615
+ fn test_thermal_zone ( ) {
616
+ let temp_dir = tempfile:: tempdir ( ) . expect ( "failed to create temporary directory" ) ;
617
+ let thermal_zone0_dir = temp_dir. path ( ) . join ( "thermal/thermal_zone0" ) ;
618
+ let thermal_zone1_dir = temp_dir. path ( ) . join ( "thermal/thermal_zone1" ) ;
619
+
620
+ // create thermal zone files
621
+ fs:: create_dir_all ( thermal_zone0_dir. join ( "device" ) )
622
+ . expect ( "failed to create thermal/thermal_zone0 directory" ) ;
623
+
624
+ fs:: write ( thermal_zone0_dir. join ( "type" ) , "test_name" )
625
+ . expect ( "failed to write to name file" ) ;
626
+ fs:: write ( thermal_zone0_dir. join ( "temp" ) , "1234" ) . expect ( "failed to write to temp file" ) ;
627
+
628
+ // create thermal zone files
629
+ fs:: create_dir_all ( thermal_zone1_dir. join ( "device" ) )
630
+ . expect ( "failed to create thermal/thermal_zone1 directory" ) ;
631
+
632
+ fs:: write ( thermal_zone1_dir. join ( "type" ) , "test_name2" )
633
+ . expect ( "failed to write to name file" ) ;
634
+ fs:: write ( thermal_zone1_dir. join ( "temp" ) , "5678" ) . expect ( "failed to write to temp file" ) ;
635
+
636
+ let mut components = ComponentsInner :: new ( ) ;
637
+ components. refresh_from_sys_class_path ( temp_dir. path ( ) ) ;
638
+ let mut components = components. into_vec ( ) ;
639
+ components. sort_by_key ( |c| c. inner . name . clone ( ) ) ;
640
+
641
+ assert_eq ! ( components. len( ) , 2 ) ;
642
+ assert_eq ! ( components[ 0 ] . inner. name, "test_name" ) ;
643
+ assert_eq ! ( components[ 0 ] . label( ) , "" ) ;
644
+ assert_eq ! ( components[ 0 ] . temperature( ) , Some ( 1.234 ) ) ;
645
+ assert_eq ! ( components[ 0 ] . max( ) , Some ( 1.234 ) ) ;
646
+ assert_eq ! ( components[ 0 ] . id( ) , Some ( "thermal_zone0" ) ) ;
647
+
648
+ assert_eq ! ( components[ 1 ] . inner. name, "test_name2" ) ;
649
+ assert_eq ! ( components[ 1 ] . label( ) , "" ) ;
650
+ assert_eq ! ( components[ 1 ] . temperature( ) , Some ( 5.678 ) ) ;
651
+ assert_eq ! ( components[ 1 ] . max( ) , Some ( 5.678 ) ) ;
652
+ assert_eq ! ( components[ 1 ] . id( ) , Some ( "thermal_zone1" ) ) ;
653
+ }
613
654
}
0 commit comments