@@ -1519,27 +1519,29 @@ TEST (PCL, LZFInMem)
1519
1519
TEST (PCL, Locale)
1520
1520
{
1521
1521
#ifndef __APPLE__
1522
+ PointCloud<PointXYZ> cloud, cloud2, cloud3;
1523
+ cloud.width = 640 ;
1524
+ cloud.height = 480 ;
1525
+ cloud.resize (cloud.width * cloud.height );
1526
+ cloud.is_dense = true ;
1527
+
1528
+ srand (static_cast <unsigned int > (time (nullptr )));
1529
+ const auto nr_p = cloud.size ();
1530
+ // Randomly create a new point cloud
1531
+ cloud[0 ].x = std::numeric_limits<float >::quiet_NaN ();
1532
+ cloud[0 ].y = std::numeric_limits<float >::quiet_NaN ();
1533
+ cloud[0 ].z = std::numeric_limits<float >::quiet_NaN ();
1534
+
1535
+ for (std::size_t i = 1 ; i < nr_p; ++i)
1536
+ {
1537
+ cloud[i].x = static_cast <float > (1024 * rand () / (RAND_MAX + 1.0 ));
1538
+ cloud[i].y = static_cast <float > (1024 * rand () / (RAND_MAX + 1.0 ));
1539
+ cloud[i].z = static_cast <float > (1024 * rand () / (RAND_MAX + 1.0 ));
1540
+ }
1541
+
1542
+ // First write with German locale, then read with English locale
1522
1543
try
1523
1544
{
1524
- PointCloud<PointXYZ> cloud, cloud2;
1525
- cloud.width = 640 ;
1526
- cloud.height = 480 ;
1527
- cloud.resize (cloud.width * cloud.height );
1528
- cloud.is_dense = true ;
1529
-
1530
- srand (static_cast <unsigned int > (time (nullptr )));
1531
- const auto nr_p = cloud.size ();
1532
- // Randomly create a new point cloud
1533
- cloud[0 ].x = std::numeric_limits<float >::quiet_NaN ();
1534
- cloud[0 ].y = std::numeric_limits<float >::quiet_NaN ();
1535
- cloud[0 ].z = std::numeric_limits<float >::quiet_NaN ();
1536
-
1537
- for (std::size_t i = 1 ; i < nr_p; ++i)
1538
- {
1539
- cloud[i].x = static_cast <float > (1024 * rand () / (RAND_MAX + 1.0 ));
1540
- cloud[i].y = static_cast <float > (1024 * rand () / (RAND_MAX + 1.0 ));
1541
- cloud[i].z = static_cast <float > (1024 * rand () / (RAND_MAX + 1.0 ));
1542
- }
1543
1545
PCDWriter writer;
1544
1546
try
1545
1547
{
@@ -1592,6 +1594,56 @@ TEST (PCL, Locale)
1592
1594
}
1593
1595
1594
1596
remove (" test_pcl_io_ascii_locale.pcd" );
1597
+
1598
+ // Now write with English locale, then read with German locale
1599
+ try
1600
+ {
1601
+ #ifdef _WIN32
1602
+ std::locale::global (std::locale (" English_US" ));
1603
+ #else
1604
+ std::locale::global (std::locale (" en_US.UTF-8" ));
1605
+ #endif
1606
+ }
1607
+ catch (const std::runtime_error&)
1608
+ {
1609
+ PCL_WARN (" Failed to set locale, skipping test.\n " );
1610
+ }
1611
+ PCDWriter writer;
1612
+ int res = writer.writeASCII <PointXYZ> (" test_pcl_io_ascii_locale.pcd" , cloud);
1613
+ EXPECT_EQ (res, 0 );
1614
+
1615
+ PCDReader reader;
1616
+ try
1617
+ {
1618
+ #ifdef _WIN32
1619
+ std::locale::global (std::locale (" German_germany" ));
1620
+ #else
1621
+ std::locale::global (std::locale (" de_DE.UTF-8" ));
1622
+ #endif
1623
+ }
1624
+ catch (const std::runtime_error&)
1625
+ {
1626
+ PCL_WARN (" Failed to set locale, skipping test.\n " );
1627
+ }
1628
+ reader.read <PointXYZ> (" test_pcl_io_ascii_locale.pcd" , cloud3);
1629
+ std::locale::global (std::locale::classic ());
1630
+
1631
+ EXPECT_EQ (cloud3.width , cloud.width );
1632
+ EXPECT_EQ (cloud3.height , cloud.height );
1633
+ EXPECT_FALSE (cloud3.is_dense );
1634
+ EXPECT_EQ (cloud3.size (), cloud.size ());
1635
+
1636
+ EXPECT_TRUE (std::isnan (cloud3[0 ].x ));
1637
+ EXPECT_TRUE (std::isnan (cloud3[0 ].y ));
1638
+ EXPECT_TRUE (std::isnan (cloud3[0 ].z ));
1639
+ for (std::size_t i = 1 ; i < cloud3.size (); ++i)
1640
+ {
1641
+ ASSERT_FLOAT_EQ (cloud3[i].x , cloud[i].x );
1642
+ ASSERT_FLOAT_EQ (cloud3[i].y , cloud[i].y );
1643
+ ASSERT_FLOAT_EQ (cloud3[i].z , cloud[i].z );
1644
+ }
1645
+
1646
+ remove (" test_pcl_io_ascii_locale.pcd" );
1595
1647
#endif
1596
1648
}
1597
1649
0 commit comments